gpt4 book ai didi

php - 为什么我一直收到 "directory does not exist?"

转载 作者:行者123 更新时间:2023-12-04 06:59:17 24 4
gpt4 key购买 nike

我无法弄清楚我在这里做错了什么。我对正在创建的文件的目录权限具有全面的写入权限。我不断收到“目录不存在”感谢您的帮助!

<?
//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);




?>

最佳答案

由于您使用的是相对路径,因此脚本很可能会假设与您假设的工作目录不同的工作目录。

您最好绝对或至少指定与 $_SERVER['DOCUMENT_ROOT'] 相关的路径。即使你这样做:

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

这样做的好处是它在您的文档根目录之外,因此您的 Web 服务器不会直接为其提供服务。无论您的脚本的位置如何,它也都可以工作,并且无论您在哪个目录下安装 Web 应用程序,它都可以工作,这可能是 dev 与 prod 部署的问题。

关于php - 为什么我一直收到 "directory does not exist?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2137345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com