bbala Posted June 16, 2008 Share Posted June 16, 2008 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 comment Share on other sites More sharing options...
pulpfiction Posted June 16, 2008 Share Posted June 16, 2008 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 comment Share on other sites More sharing options...
bbala Posted June 17, 2008 Author Share Posted June 17, 2008 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 comment Share on other sites More sharing options...
Wander Posted June 17, 2008 Share Posted June 17, 2008 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 comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2008 Share Posted June 17, 2008 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 comment Share on other sites More sharing options...
bbala Posted June 17, 2008 Author Share Posted June 17, 2008 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 comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2008 Share Posted June 17, 2008 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 comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.