【发布时间】:2015-12-01 09:03:42
【问题描述】:
我正在尝试使用以下代码将图像从 tmp 目录移动/复制/上传到另一个目录,但我没有看到我的图像被移动/复制到目标。有没有其他选择?
public function uploadToS3($file, $tmp_url) {
if (strrpos($file, '.tmp') == strlen($file)-4) {
$file = substr($file, 0, strlen($file)-4);
}
$destination = "var/www/html/image" . $file;
if (file_exists($destination)) {
echo 'File '. $destination. ' already exists!';
} else {
move_uploaded_file($tmp_url, $destination);
}
}
//Ex: $tmp_url = http://localhost/mage/media/tmp/catalog/product/s/c/abc.png
//Ex: $destination = /var/www/html/image/s/c/abc.png
在下面的 cmets 之后,我尝试了以下 php 代码,但也失败了
<?php
$tmp_url = "var/www/html/abc/abc.png";
$destination = "var/www/html/des/abc.png";
if(move_uploaded_file($tmp_url, $destination)){echo "success";}else{echo "fail";}
【问题讨论】:
-
也许你错过了 $destination = "var/www/html/image" 中的起始 / 。 $文件;
-
执行 if(move_uploaded_file($tmp_url, $destination)){echo "success";}else{echo "fail";} 并发布输出...完成
-
@WilliamMadede:它说失败。
-
你怎么称呼你的函数
uploadToS3?? -
更新 $destination = "var/www/html/image" 。 $文件;到 $destination = "var/www/html/image/" 。 $文件;
标签: php file-upload