无法打开流:没有这样的文件或目录,但目录存在。在本地主机上工作但不在实时站点上工作[重复]

Posted

技术标签:

【中文标题】无法打开流:没有这样的文件或目录,但目录存在。在本地主机上工作但不在实时站点上工作[重复]【英文标题】:Failed to open stream: No such file or directory But Directory Exists. Working on localhost but not on live site [duplicate] 【发布时间】:2020-11-26 03:05:16 【问题描述】:

我正在尝试将文件上传到目录。目录存在,但它说

Warning: move_uploaded_file(/home/icq3zr1l9m6h/public_html/wp-content/uploads/jambalaio/logo/AF_Logo_APP_Branco [Converted].png): failed to open stream: No such file or directory in /home/icq3zr1l9m6h/public_html/wp-content/themes/astra-child/includes/jambalaioApp.php on line 14

这在本地主机上运行良好,但在实时站点上运行不正常。 你能告诉我可能的错误是什么!

代码是

$target_dir_logo = ABSPATH."wp-content/uploads/jambalaio/logo/";
$target_file_logo = $target_dir_logo . basename($_FILES["logo"]["name"]);
//$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file_logo,PATHINFO_EXTENSION));
move_uploaded_file($_FILES["logo"]["tmp_name"], $target_file_logo);

$target_dir_bg = ABSPATH."wp-content/uploads/jambalaio/background/";
$target_file_bg = $target_dir_bg . basename($_FILES["bg-image"]["name"]);
//$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file_bg,PATHINFO_EXTENSION));
move_uploaded_file($_FILES["bg-image"]["tmp_name"], $target_file_bg);

【问题讨论】:

【参考方案1】:

这个错误可能是因为 PHP 对 /home/user 文件夹没有可见性。 我通常使用源自网站 ROOT 的路径,而不是 OS ROOT。

编辑:顺便说一句,确保这些文件夹具有适当的权限。

【讨论】:

以上是关于无法打开流:没有这样的文件或目录,但目录存在。在本地主机上工作但不在实时站点上工作[重复]的主要内容,如果未能解决你的问题,请参考以下文章

Laravel 5 显示 ErrorException file_put_contents 无法打开流:没有这样的文件或目录

无法打开流:[重复]中没有这样的文件或目录

Require_once 无法打开流:没有这样的文件或目录

无法打开流:没有这样的文件或目录(Laravel)

图片上传错误无法打开流:没有这样的文件或目录

PHP警告:无法打开流:没有这样的文件或目录,文件路径错误