waynew Posted June 20, 2008 Share Posted June 20, 2008 For some strange reason, I can't seem to be able to open a text file that definately exists. My code: <?php $fp = fopen("C:\hello.txt", 'w+'); $letter = fread($fp, filesize($fp)); ?> <htmL><body><?php fclose($fp); echo $letter; ?></body></htmL> Link to comment https://forums.phpfreaks.com/topic/111088-solved-text-file-problems/ Share on other sites More sharing options...
GingerRobot Posted June 20, 2008 Share Posted June 20, 2008 Two problems: 1.) filesize() expects the filename not the resource handler. 2.) If you want to read existing data, you'll need r, not w -- using w wipes the file first. (see: http://www.php.net/fopen) So: $fp = fopen("C:\hello.txt", 'r+'); $letter = fread($fp, fileszie("C:\hello.txt")); Link to comment https://forums.phpfreaks.com/topic/111088-solved-text-file-problems/#findComment-570077 Share on other sites More sharing options...
waynew Posted June 20, 2008 Author Share Posted June 20, 2008 Thanks GingerRobot!! Link to comment https://forums.phpfreaks.com/topic/111088-solved-text-file-problems/#findComment-570095 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.