Jump to content

php file


Recommended Posts

i try to read a text file and print the contents... but no content is displayed..here is the link to it http://bbala2020.freeweb7.com/test.phpis the error in php script or hosting site or the url?????

<?phpecho "<br>";$handle = fopen("http://www.amfiindia.com/portal/upload/downloadnav.txt", "rb");$content1 = stream_get_contents($handle);echo $content1;$content2 = fread($handle,100);echo $content2;$content3 = fgets($handle);echo $content3;echo "hii testing!!!!";fclose($handle);?>

Link to post
Share on other sites

Im not a PHP expert, just try displaying the whole file.

<?phpecho "<br>";$myFile = "http://www.amfiindia.com/portal/upload/downloadnav.txt";$handle = fopen($myFile, 'rb');$theData = fread($handle, filesize($myFile));fclose($fh);echo $theData;echo "hii testing!!!!";fclose($handle);?>

i try to read a text file and print the contents... but no content is displayed..here is the link to it http://bbala2020.freeweb7.com/test.phpis the error in php script or hosting site or the url?????
<?phpecho "<br>";$handle = fopen("http://www.amfiindia.com/portal/upload/downloadnav.txt", "rb");$content1 = stream_get_contents($handle);echo $content1;$content2 = fread($handle,100);echo $content2;$content3 = fgets($handle);echo $content3;echo "hii testing!!!!";fclose($handle);?>

Link to post
Share on other sites

not much diff in the code..

<?phpecho "<br>";$myFile = "http://www.amfiindia.com/portal/upload/downloadnav.txt";$handle = fopen($myFile, 'rb');$theData = fread($handle, filesize($myFile));fclose($fh);echo $theData;echo "hii testing!!!!";fclose($handle);?>

i tried this too it didnt work..

Link to post
Share on other sites

as 2nd parameter for fopen ur using 'rb', as far as i know there is no such thing, try just using 'r'in fread u also use filesize() with an url, this doesnt work below php5, but if you use php5, i think you can also just use file_get_contents() instead of fopen+fread+fclose

Link to post
Share on other sites

If you append 'b' to any mode it opens it in binary mode instead, you can use it with any of the other modes. It's actually preferred to use it on Windows systems at least.The first fclose statement is causing an error before you print the data, $fh doesn't exist. Try this:

<?php$myFile = "http://www.amfiindia.com/portal/upload/downloadnav.txt";$data = file_get_contents($myFile);echo $data;?>

There might also be issues on your server with trying to open files over http. If that doesn't work you may need to open a socket connection and get the data that way.

Link to post
Share on other sites

the result was the same :)http://bbala2020.freeweb7.com/test3.phpthe server uses php 5 (said so)is there any function similar to mysql_error for showing php errors?? how to open a socket connection ? i actually want to process this text file and store it in a database. http://www.amfiindia.com/portal/upload/downloadnav.txtIs there any way to make this script run at some specified time daily?

Link to post
Share on other sites

You can use this to make sure that error messages show up:ini_set("display_errors", 1);error_reporting(E_ALL);You can use this to open a socket:http://www.php.net/manual/en/function.fsockopen.phpOn a Linux server you can use a utility called cron to schedule things to run, and Windows has the task scheduler.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...