dennismonsewicz Posted December 9, 2009 Share Posted December 9, 2009 I am trying to write some test content to my CSV file and when I run my script everything seems to work properly but when I view the file nothing is in the CSV doc. Code: <?php $file = 'file.csv'; $somecontent = "Hello World"; if(is_writable($file)) { $fp = fopen($file, 'w'); if (!$handle = fopen($file, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($fp); echo 'Hello World'; } else { echo 'File not writable'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/184557-fwrite-problems/ Share on other sites More sharing options...
premiso Posted December 9, 2009 Share Posted December 9, 2009 You are not closing the file properly. fclose($fp); Should be: fclose($handle); Fix that and see if that solves your problem. Quote Link to comment https://forums.phpfreaks.com/topic/184557-fwrite-problems/#findComment-974348 Share on other sites More sharing options...
dennismonsewicz Posted December 9, 2009 Author Share Posted December 9, 2009 Thanks for your help, but that did not fix the problem I think it is a permissions problem because I tried it locally and it works, but not on the webserver... Quote Link to comment https://forums.phpfreaks.com/topic/184557-fwrite-problems/#findComment-974354 Share on other sites More sharing options...
nomadrw Posted December 9, 2009 Share Posted December 9, 2009 Yes you have a permission problem, go into the admin on the host site and change it. Please note every time you open this script you will over write your file.cvs. Quote Link to comment https://forums.phpfreaks.com/topic/184557-fwrite-problems/#findComment-974409 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.