olegshilkrut Posted November 8, 2009 Share Posted November 8, 2009 hi all cant figure out how to write to file uisng this code <html> <body> <?php $myFile = "test.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Bobby Bopper\n"; fwrite($fh, $stringData); $stringData = "Tracy Tanner\n"; fwrite($fh, $stringData); fclose($fh); ?> </body> </html> please help me out here Link to comment https://forums.phpfreaks.com/topic/180717-cannot-write-to-file/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2009 Share Posted November 8, 2009 You would need to tell us what problem you are having when you tried that code, because there is nothing wrong with it and it in fact worked for me when I tried it. Link to comment https://forums.phpfreaks.com/topic/180717-cannot-write-to-file/#findComment-953449 Share on other sites More sharing options...
Joshua4550 Posted November 8, 2009 Share Posted November 8, 2009 The code is fine, as mentioned above; However, you should make sure that the file permissions are set appropriatly. Link to comment https://forums.phpfreaks.com/topic/180717-cannot-write-to-file/#findComment-953454 Share on other sites More sharing options...
ramyakumar Posted November 8, 2009 Share Posted November 8, 2009 I had the same problem but later I used getFilename instead of using filename directly in the fopen. This link should help you. http://roshanbh.com.np/2008/01/getting-filename-and-extension-in-php-using-explode-and-pathinfo.html Link to comment https://forums.phpfreaks.com/topic/180717-cannot-write-to-file/#findComment-953548 Share on other sites More sharing options...
bob2588 Posted November 8, 2009 Share Posted November 8, 2009 you might also want to try thisfile_put_contents Link to comment https://forums.phpfreaks.com/topic/180717-cannot-write-to-file/#findComment-953572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.