如何在godaddy服务器上传图像数组?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在godaddy服务器上传图像数组?相关的知识,希望对你有一定的参考价值。
我编写代码因为我需要将多个图像上传到我的网站以显示一些细节。我正在将我的网站设置为godaddy服务器并且发生了一些错误,但是上传多个图像的这个错误无效。它适用于localhost。这是我得到的错误:
[28-Mar-2019 03:18:43 UTC] php警告:move_uploaded_file():copy()函数的第二个参数不能是第123行/home/v1pyvnw05stp/public_html/**.php中的目录[28- Mar-2019 03:18:43 UTC] PHP警告:move_uploaded_file():无法移动;
当我查看文件夹时,我注意到他们不应该在一个地方至少有两个图像,而是作为test / x-generic文件
$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.
}
}
我已经改变了许可
您在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);
}
}
不要使用服务器目录的绝对路径。
替换$ uploadPath ='/ home / v1pyvnw05stp / public_html / images / Articulos /'。$ upload;使用$ _SERVER ['DOCUMENT_ROOT']。'images / Articulos /'.$ uploadName;
用move_uploaded_file($tmpLoc[$i],$uploadPath[$i]);
替换
move_uploaded_file($ tmpLoc [$ i]于,$ uploadPath);
我弄明白为什么我得到了这个错误,因为我应该将[]添加到$ 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]);
}
以上是关于如何在godaddy服务器上传图像数组?的主要内容,如果未能解决你的问题,请参考以下文章