2017-07-07 42 views
0

我写了下面的代码。但是我没有价值的空$_FILES[“image”][“tmp_name”]

PHP的:

if ($_FILES) { 
$imageFileType = strtolower(pathinfo("img/" . basename($_FILES["Image"]["name"]), PATHINFO_EXTENSION)); 

$target_file = "img/" . uniqid(rand()) . ".$imageFileType"; 
if (move_uploaded_file($_FILES["Image"]["tmp_name"], $target_file)) { 
    $pic = $target_file;  
} else { 

    echo "Invalid File"; 
    } 
} 

HTML:

<form action="product-add.php" method="post" enctype="multipart/form-data"> 
     <div class="products-form"> 
      <p> Image:</p> <input type="file" name="Image" > 
      <input type="submit" value="ADD PRODUCT" class="btn"> 
     </div> 
</form> 
+7

将'print_r($ _ FILES);'添加到代码的顶部并重新提交。向我们展示这个数组。 –

回答

0

那么在我看来,这是不对的:

$target_file = "img/" . uniqid(rand()) . ".$imageFileType"; 

应该

$target_file = "img/" . uniqid(rand()) . "." .$imageFileType; 
相关问题