我写了以下代码。但是我的空$_FILES[“image”][“tmp_name”]
没有价值。
腓:
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>
答案 0 :(得分:0)
在我看来,这是不对的:
$target_file = "img/" . uniqid(rand()) . ".$imageFileType";
应该是
$target_file = "img/" . uniqid(rand()) . "." .$imageFileType;