Zeradin Posted July 22, 2008 Share Posted July 22, 2008 Ok so I'm a newb, but I've been working really hard at learning PHP and I've done a really good job I think but I can't figure out why I can't write to a text file. I've chmod the file to 777, I've tried changing the way the writing's being done, tried deleting it, tried appending instead of writing... I even simplified to try and just write "hi". here's the code. Please help. Thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Uploaded?</title> <link href="cssface.css" rel="stylesheet" type="text/css" /> </head> <body text=#FFFFFF><br /> <?php if(isset($_POST['newssubmit'])) { $title = $_POST['title']; $date = $_POST['date']; $time = $_POST['time']; $poster = $_POST['poster']; $news = $_POST['message']; foreach($_POST['check'] as $value) { $check_type .= "Checked: $value\n"; } // set file to write $file = "http://hypboard.com/thehyp/generalnews.txt"; // open file $fh = fopen($file, 'w') or die('Could not open file!'); // write to file fwrite($fh, "hi ") or die('Could not write to file'); // close file fclose($fh); echo " It might have worked? "; echo $title; echo $date; echo $time; echo $poster; echo $news;; echo $check_type; } else { echo "doh"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/ Share on other sites More sharing options...
awpti Posted July 22, 2008 Share Posted July 22, 2008 How about you look at your webserver log files? That will give you a better clue as to what's going on. And probably provide a slightly more accurate error. Code is meaningless in this case. Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596135 Share on other sites More sharing options...
Zeradin Posted July 22, 2008 Author Share Posted July 22, 2008 [Mon Jul 21 22:49:42 2008] [error] [client 67.225.204.158] File does not exist: /home/hypboard/public_html/403.shtml [Mon Jul 21 22:49:42 2008] [error] [client 67.225.204.158] (13)Permission denied: file permissions deny server access: /home/hypboard/public_html/thehyp/generalnews.txt but the file does exist? http://hypboard.com/thehyp/generalnews.txt Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596139 Share on other sites More sharing options...
Zeradin Posted July 22, 2008 Author Share Posted July 22, 2008 I think it's actually giving me can not write to file. Bump. Help? Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596563 Share on other sites More sharing options...
DoddsAntS Posted July 22, 2008 Share Posted July 22, 2008 Hi, Try using the file system path to the file instead of the url to the file so replace http://hypboard.com/thehyp/generalnews.txt with /home/hypboard/public_html/thehyp/generalnews.txt Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596567 Share on other sites More sharing options...
waynew Posted July 22, 2008 Share Posted July 22, 2008 Check the permissions of the folder. Is it allowed to write? Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596620 Share on other sites More sharing options...
Zeradin Posted July 22, 2008 Author Share Posted July 22, 2008 no neither worked... I can't check the log from here but my assumption is that it's the same thing. =( what the hell Also I can't modify my first post. The actual error is "Could not write to file" not could not open file. Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596640 Share on other sites More sharing options...
Zeradin Posted July 22, 2008 Author Share Posted July 22, 2008 D'oh, just realized the problem: You're trying to use a URL to open the file for writing. Apache doesn't allow this because that'd be rediculous; would you want everyone in the world writing to files on your website? Instead, you have to use a local path on the filesystem itself. This can either be a relative path (e.g. "../myfile.txt" or "some/dir/myfile.txt") or an absolute path (e.g. "/home/username/www/myfile.txt" or $_SERVER['DOCUMENT_ROOT'] . "/some/dir/myfile.txt"). solved on php builder. Thanks anyway guys! Quote Link to comment https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/#findComment-596687 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.