【发布时间】:2021-04-07 17:54:25
【问题描述】:
你写了简单的代码来重命名我在服务器上的文件,但总是出现如下错误
rename(/public_html/mystore/images,/public_html/mystore/images/test.jpeg): No such file or directory in /home/innovero/public_html/mystore/move.php on line 18
下面是重命名的PHP代码,
<?php
/* Store the path of source file */
$filePath = '/public_html/mystore/test.jpeg';
/* Store the path of destination file */
$destinationFilePath = '/public_html/mystore/images/test.jpeg';
/* Copy File from images to copyImages folder */
if( !rename($filePath, $destinationFilePath) ) {
echo "File can't be moved!";
}
else {
echo "File has been moved!";
}
?>
我的代码有什么问题,我的 move.php 位于 mystore 文件夹中,我想将文件从 mystore 移动到作为 mystore 子文件夹的 images 文件夹。请帮忙
【问题讨论】:
-
前导斜杠表示文件存储在文件系统的根目录,与当前脚本无关
-
你能建议什么是正确的路径写入方式。
-
更新了错误,将 / 替换为 ./ 作为重命名(./public_html/mystore/images,./public_html/mystore/images/test.jpeg):/home/innovero 中没有这样的文件或目录/public_html/mystore/move.php 第 18 行
-
然后使用完整路径:
/home/innovero/public_html/... -
您到底想在此处复制/移动什么文件?来自
$filePath = '/public_html/mystore/images';:public_html/mystore/images是一个文件吗?