我正在尝试将在我的名为“upload”的目录中名为 image (5).jpg 的上传文件复制到另一个名为“images”的目录中。这是我的代码。
<?php
copy(upload/image (5).jpg, images/);
?>
我这样做对吗?
首先,您的图像文件名很糟糕,请不要在文件名中使用空格。也不要在文件名中使用括号。谷歌应用引擎等一些系统很容易将其标记为无效文件名并忽略它。
然后稍微调整一下你的代码行,如下所示:
$old_file = 'upload/image_5.jpg';
$new_file = 'images/image_5.jpg';
$copied = copy(old_file, $new_file);
if ($copied) {
print "file " . $old_file . " is copied to " . $new_file;
} else {
print "error";
}
如果遇到错误,可能文件路径配置不正确。您对该特定目录等没有写入权限。