ballhogjoni Posted January 5, 2009 Share Posted January 5, 2009 I am using fopen() to create a file on my local server, but it seems to not be working. What am I doing wrong? code: $fh = fopen('local/path/to/file/test.csv','w'); fwrite($fh,$csv_output); fclose($fh); Quote Link to comment https://forums.phpfreaks.com/topic/139566-solved-how-to-create-a-file-in-a-specific-directory/ Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 What error are you getting? Are you using Windows or Linux? Quote Link to comment https://forums.phpfreaks.com/topic/139566-solved-how-to-create-a-file-in-a-specific-directory/#findComment-730103 Share on other sites More sharing options...
ballhogjoni Posted January 5, 2009 Author Share Posted January 5, 2009 not getting an error and I have errors on. There is no file in the directory. also I am on windows, but when I am done creating the file I will upload to linux server. Quote Link to comment https://forums.phpfreaks.com/topic/139566-solved-how-to-create-a-file-in-a-specific-directory/#findComment-730105 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 Maybe try this: <?php if (file_exists('local/path/to/file/test.csv')) { echo 'The file exists...grabbing the contents<br />'; $file = file_get_contents('local/path/to/file/test.csv'); echo nl2br($file); echo '<br />End of the file!'; }else { $fh = fopen('local/path/to/file/test.csv','w'); fwrite($fh,$csv_output); fclose($fh); } ?> And see what that displays. It may be writing it but for whatever reason you cannot see it?? Quote Link to comment https://forums.phpfreaks.com/topic/139566-solved-how-to-create-a-file-in-a-specific-directory/#findComment-730108 Share on other sites More sharing options...
ballhogjoni Posted January 5, 2009 Author Share Posted January 5, 2009 ok...I tried that and it always does the else, which makes me think that I can't create a file because of my apache settings or can't create a file in the local environment. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/139566-solved-how-to-create-a-file-in-a-specific-directory/#findComment-730119 Share on other sites More sharing options...
ballhogjoni Posted January 5, 2009 Author Share Posted January 5, 2009 ok it worked...I was using a defined file path that was incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/139566-solved-how-to-create-a-file-in-a-specific-directory/#findComment-730122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.