我编写代码是因为我需要将多个图像上传到我的网站上以显示一些详细信息。我正在将我的网站设置为godaddy服务器,但发生了一些错误,但是上载多张图片的这一操作不起作用。它在本地主机上工作。这是我得到的错误:
[2019年3月28日03:18:43 UTC] PHP警告:move_uploaded_file(): copy()函数的第二个参数不能是以下目录 /home/v1pyvnw05stp/public_html/**.php,第123行[2019年3月28日 03:18:43 UTC] PHP警告:move_uploaded_file():无法移动;
当我查看文件夹时,我注意到在一个地方至少有两个图像是不应该的,但它们应该是测试/ x通用文件
$photocount = count($_FILES['photo']['name']);
if ($photocount > 0) {
for($i = 0; $i<$photocount;$i++){
$name = $_FILES['photo']['name'][$i];
$nameArray = explode('.',$name);
$filename=$nameArray[0];
$fileExt = $nameArray[1];
$mime = explode('/',$_FILES['photo']['type'][$i]);
$mimeType = $mime[0];
$mimeExt = $mime[1];
$tmpLoc[] = $_FILES['photo']['tmp_name'][$i];
$fileSize = $_FILES['photo']['size'][$i];
$uploadName = md5(microtime().$i).'.'.$fileExt;
$uploadPath = '/home/v1pyvnw05stp/public_html/images/Articulos/'.$uploadName;
if($i != 0){
$dbpath .= ',';
}
$dbpath = '/images/Articulos/'.$uploadName;
if($photocount > 0){
for($i = 0;$i<$photocount;$i++){
move_uploaded_file($tmpLoc[$i],$uploadPath[$i]); THIS IS THE ERROR LINE AND IF I ERASE $I OF $UPLOADPAH THE SISTEM WORK BUT JUST WITH ONE IMAGE.
}
}
我已经更改了权限
答案 0 :(得分:0)
在遇到错误时,您在move_uploaded_file()
方法中传递了错误的参数。第二个arg $uploadPath[$i]
不是数组,而是代码中定义的字符串。进行以下更改,
$photocount = count($_FILES['photo']['name']);
if ($photocount > 0) {
for($i = 0; $i<$photocount;$i++){
$name = $_FILES['photo']['name'][$i];
$nameArray = explode('.',$name);
$filename=$nameArray[0];
$fileExt = $nameArray[1];
$mime = explode('/',$_FILES['photo']['type'][$i]);
$mimeType = $mime[0];
$mimeExt = $mime[1];
$tmpLoc[] = $_FILES['photo']['tmp_name'][$i];
$fileSize = $_FILES['photo']['size'][$i];
$uploadName = md5(microtime().$i).'.'.$fileExt;
$uploadPath = '/home/v1pyvnw05stp/public_html/images/Articulos/'.$uploadName;
if($i != 0){
$dbpath .= ',';
}
$dbpath = '/images/Articulos/'.$uploadName;
if($photocount > 0){
for($i = 0;$i<$photocount;$i++){
move_uploaded_file($tmpLoc[$i],$uploadPath);
}
}
答案 1 :(得分:0)
请勿使用服务器目录的绝对路径。
替换$ uploadPath ='/home/v1pyvnw05stp/public_html/images/Articulos/'.$uploadName; 与$ _SERVER ['DOCUMENT_ROOT']。'images / Articulos /'.$ uploadName;
替换move_uploaded_file($tmpLoc[$i],$uploadPath[$i]);
move_uploaded_file($ tmpLoc [$ i],$ uploadPath);
答案 2 :(得分:0)
我弄清楚了为什么出现此错误,是因为我应该在$ uploadpath中添加[]。现在,我没有收到错误,但是我不能向数据库添加多个$ dbpath。为什么有一些想法?
$uploadPath**[]** = '/home/v1pyvnw05stp/public_html/images/Articulos/'.$uploadName;
if($photocount > 0){
for($i = 0;$i<$photocount;$i++){
move_uploaded_file($tmpLoc[$i],$uploadPath[$i]);
}