Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/115943-solved-could-not-open-file/
Share on other sites

[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

 

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.