警告:move_uploaded_file():无法打开流:没有这样的文件或目录和警告:move_uploaded_file():无法移动

时间:2016-10-18 18:58:13

标签: php

如果我尝试上传数组文件类型中的多个文件,我会收到这些错误..但如果我尝试上传一张上传的图片:\

这是我的HTML

<form action="" method="post" enctype="multipart/form-data">   
<label for="product1"> Image 1 </label> <input type="file" name="productimages1[]" id="product1" /> 
<label for="product1"> Image 2 </label> <input type="file" name="productimages2[]" id="product1" /> 
<label for="product1"> Image 3 </label> <input type="file" name="productimages3[]" id="product1" /> 
<label for="product1"> Image 4 </label> <input type="file" name="productimages4[]" id="product1" /> <br /> 
<input type="submit" name="save" />
</form>

而php就是

$image1 = $_FILES['productimages1']['name'];
$image1temp = $_FILES['productimages1']['tmp_name'];
$image2 = $_FILES['productimages2']['name'];
$image2temp = $_FILES['productimages2']['tmp_name'];
$image3 = $_FILES['productimages3']['name'];
$image3temp = $_FILES['productimages3']['tmp_name'];
$image4 = $_FILES['productimages4']['name'];
$image4temp = $_FILES['productimages4']['tmp_name'];
$target_dir = "../uploads/store/products/";



$result = array();    
//$result = mergeArrays($codes, $name, $price, $discount, $description, $category, $quantity, $image1, $image2, $image3, $image4,$image1temp,$image2temp,$image3temp,$image4temp);
$result = mergeArrays2($image1temp,$image2temp,$image3temp,$image4temp,$image1,$image2,$image3,$image4);
foreach($result as $row)
{
    $target_file1 = $target_dir . basename($row["name1"]);
    $uploadOk = 1;
    $imageFileType1 = pathinfo($target_file1,PATHINFO_EXTENSION);
    $target_file2 = $target_dir . basename($row["name2"]);
    $uploadOk = 1;
    $imageFileType2 = pathinfo($target_file2,PATHINFO_EXTENSION);
    $target_file3 = $target_dir . basename($row["name3"]);
    $uploadOk = 1;
    $imageFileType3 = pathinfo($target_file3,PATHINFO_EXTENSION);
    $target_file4 = $target_dir . basename($row["name4"]);
    $uploadOk = 1;
    $imageFileType4 = pathinfo($target_file4,PATHINFO_EXTENSION);

    if (move_uploaded_file($row['tmp_name1'], $target_file1)) 
    {
        echo "\n"."The file ". basename( $row['name1']). " has been uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file." ."<<".$imageFileType1. ">>" .$target_file1 . "...".$row["name1"]."...".$row["tmp_name1"];
    }
    if (move_uploaded_file($row['tmp_name2'], $target_file2)) 
    {
        echo "\n"."The file ". basename( $row['name2']). " has been uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file." ."<<".$imageFileType2. ">>" .$target_file2 . "...".$row["name2"]."...".$row["tmp_name2"];
    }
    if (move_uploaded_file($row['tmp_name3'], $target_file3)) 
    {
        echo "\n"."The file ". basename( $row['name3']). " has been uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file." ."<<".$imageFileType3. ">>" .$target_file3 . "...".$row["name3"]."...".$row["tmp_name3"];
    }
    if (move_uploaded_file($row['tmp_name4'], $target_file4)) 
    {
        echo "\n"."The file ". basename( $row['name4']). " has been uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file." ."<<".$imageFileType4. ">>" .$target_file4 . "...".$row["name4"]."...".$row["tmp_name4"];
    }
    $img1 = basename($row["name1"]);
    $img2 = basename($row["name2"]);
    $img3 = basename($row["name3"]);
    $img4 = basename($row["name4"]);
}

函数mergeArray2就是这个

function mergeArrays2($image1temp,$image2temp ,$image3temp,$image4temp,$image1, $image2, $image3, $image4) 
{
    $result = array();
    $i=0;
    foreach($image1temp as $key=>$image1temps) {
        $result[] = array('tmp_name1'=> $image1temps, 'tmp_name2'=>     $image2temp[$key],'tmp_name3'=> $image3temp[$key],'tmp_name4'=> $image4temp[$key],'tmp_name1'=> $image1temp[$key],'name1'=> $image1[$key],'name2' => $image2[$key],'name3'=> $image3[$key],'name4'=> $image4[$key]);
    }

    return $result;
}

0 个答案:

没有答案