【发布时间】:2016-01-06 04:04:19
【问题描述】:
我的 PHP 图像上传器出现问题,因为某种原因,当我测试时,尽管选择了图像,但它仍在回显 NULL,而不是图像 URL。这可能是什么原因?
if (isset($_POST['add_product'])) {
include 'connect.php';
$prodname = (isset($_POST['productname']) ? $_POST['productname'] : null);
$prodtype = (isset($_POST['prodtype']) ? $_POST['prodtype'] : null);
if (empty($_FILES['prodimage']['name'])) {
$imageURL = "NULL";
echo $prodname."<br>".$prodtype."<br>".$imageURL;
} else if (!empty($_FILES['prodimage']['name'])) {
if(move_uploaded_file($_FILES['prodimage']['tmp_name'], "../media/images/" .$_FILES['prodimage']['name']))
$imageURL = "media/images/" .$_FILES['prodimage']['name'];
echo $prodname."<br>".$prodtype."<br>".$imageURL;
}
}
HTML 代码:
<h2>Add Products</h2>
<form action='' method="POST">
<div class='products'>
<h3>Product Name</h3>
<input type='text' name='productname' class='title' placeholder='' value=''/>
</div>
<div class='products'>
<h3>Product Type</h3>
<div class='styled-select'>
<select name='prodtype'><OPTION VALUE='1'>MARMORSKIVOR</OPTION>
<OPTION VALUE='2'>GRANIT</OPTION>
</select>
</div>
</div>
<div class='products'>
<h3>Add image</h3>
<label class="myLabel" id="prodimage">
<input type="file" name="prodimage" id="fileToUpload" />
<span>Select Image</span>
</label>
</div>
<div class="products">
<button class='add_product' type='submit' name='add_product'>Add Product</button>
</div>
</form>
【问题讨论】:
标签: php image-uploading