开发者

Why do I keep getting "directory does not exist?"

I cannot figure out what I am doing wrong here. The permissions for the directory I have for the file being created have write permissions all across the board. I keep getting "directory does not 开发者_开发知识库exist" Thanks for the help!

<?
//creates variables and calls the information from the server
$Name = $_POST['name'];
$desc = $_POST['desc'];
$website =$_POST['web'];
$email =$_POST['email'];
$cname =$_POST['cname'];
echo "your registered name is: ". $Name . ".<br/>";
echo "your registered description is: " . $desc . ".<br/>";
echo "your website address is: " . $website . ".<br/>";
echo "your Confirmation email has been sent to: " . $email . ".<br/>";

echo "your information has been stored, thank you! ";

$cname = trim($cname);

$filename = "data/clubinfo/$cname.txt";
$fp = fopen($filename,'a');
fwrite($fp,$Name);
fwrite($fp,"\n");
fwrite($fp,$email);
fwrite($fp,"\n");
fwrite($fp,$desc);
fwrite($fp,"\n");
fwrite($fp, $website);
fwrite($fp, "\n");
fwrite($fp,"__");
fwrite($fp, "\n");
fclose($fp);




 ?>


Most likely the script is assuming a different working directory to what you're presuming since you're using a relative path.

You'd be better off specifying the path absolutely or at least in relation to $_SERVER['DOCUMENT_ROOT'] even if you do:

$filename = $_SERVER['DOCUMENT_ROOT'] . "../data/clubinfo/$cname.txt";

The advantage of that is that it's outside your document root so it won't be served directly by your Web server. It will also work no matter the location of your script and will work no matter under what directory you install your Webapp, which can be an issue with dev vs prod deployments.


The data/clubinfo folder does not exist in the current directory.

You need to create it first. (By hand or in PHP)
Alternatively, the current directory might not be what you think it is.


Try using file_put_contents() like this:

file_put_contents("data/clubinfo/$cname.txt", implode("\n", $_POST));

If you want to this value by value you should also use the FILE_APPEND flag.


looks like you have not given the path off the root and the server is looking from the current location. try giving the path off the root.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜