refiking Posted June 16, 2009 Share Posted June 16, 2009 I am trying to write a php file. I have no problems with txt or csv. What am I missing? <?php $filename = 'testing.php'; $somecontent = "Add this to the file\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, '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; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/ Share on other sites More sharing options...
rhodesa Posted June 16, 2009 Share Posted June 16, 2009 works fine for me...what is your error? Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/#findComment-857361 Share on other sites More sharing options...
refiking Posted June 16, 2009 Author Share Posted June 16, 2009 The file testing.php is not writable Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/#findComment-857364 Share on other sites More sharing options...
rhodesa Posted June 16, 2009 Share Posted June 16, 2009 Does the file exist? Does the webserver have access to write to the file? Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/#findComment-857368 Share on other sites More sharing options...
refiking Posted June 16, 2009 Author Share Posted June 16, 2009 The file exists. Not sure how to give access to make it writeable. CHMOD it to 777 already. File and folder. As I said, it'll work on txt files. Is this another setting or something? Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/#findComment-857372 Share on other sites More sharing options...
rhodesa Posted June 16, 2009 Share Posted June 16, 2009 hum...could be...you can try letting the web process create it too. delete the file, then in your code add to the top: <?php $filename = 'testing.php'; $somecontent = "Add this to the file\n"; if(!file_exists($filename)){ fclose(fopen('testing.php','w+')); } // Let's make sure the file exists and is writable first. if (is_writable($filename)) { ...rest of code Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/#findComment-857376 Share on other sites More sharing options...
refiking Posted June 16, 2009 Author Share Posted June 16, 2009 YOU ROCK Link to comment https://forums.phpfreaks.com/topic/162429-solved-trouble-w-fwrite/#findComment-857379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.