我正在创建一个项目表单,管理员可以向库存中添加项目和它们的图像。我想将图像保存为“$item_id.jpg”在“img/items”文件夹中。不幸的是,我的项目被添加到数据库中,但文件并没有上传到指定的文件夹。以下是我的代码,非常感谢你的帮助。
//Code for the form----------------------------------------------
<form class="stock" method="post" action="">
<table class="newstocktable">
<tr>
<th>Size:</th>
<td>
<select name= "size">
<option> </option>
<?php
require ('connection.php');
$query = mysql_query("SELECT * FROM fyp_size")or die(mysql_error());
while($result = mysql_fetch_array($query)){
echo '<option>'.$result['size'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>Item name:</th>
<td>
<input type="text" name="name" id="Name" <?php if (isset($_POST['name'])=== true){echo 'value="', strip_tags($_POST['name']),'"';}?>>
</td>
</tr>
<tr>
<th>Description: </th>
<td>
<textarea name="desc" <?php if (isset($_POST['desc'])=== true){echo 'value="', strip_tags($_POST['desc']),'"';}?>></textarea>
</td>
</tr>
<tr>
<th>Price (£): </th>
<td>
<input type="text" name="price" <?php if (isset($_POST['price'])=== true){echo 'value="', strip_tags($_POST['price']),'"';}?>>
</td>
</tr>
<tr>
<th>Quantity: </th>
<td>
<input type="text" name="quantity" <?php if (isset($_POST['quantity'])=== true){echo 'value="', strip_tags($_POST['quantity']),'"';}?>>
</td>
</tr>
<tr>
<th>Threshold: </th>
<td>
<input type="text" name="threshold" <?php if (isset($_POST['threshold'])=== true){echo 'value="', strip_tags($_POST['threshold']),'"';}?>>
</td>
</tr>
<tr>
<th>Product image:</th>
<td>
<input type="file" name="item_img" id="item_img">
</td>
</tr>
<tr>
<td>
<input type="submit" name="addnewstock" value= "Add Stock">
</td>
</tr>
</table>
//PHP parsing code-------------------------------------
$query = mysql_query("SELECT * FROM items WHERE name='$name' &&
size_id='$sizeid'")or die(mysql_error());
$numrows = mysql_num_rows($query);
if($numrows == 0){
mysql_query("INSERT INTO items VALUES(
'', '$sizeid', '$name', '$desc', '$price', '$quantity', '$threshold', now()
)")or die(mysql_error());
$item_id = mysql_insert_id();
$query = mysql_query("SELECT * FROM items WHERE name='$name'")or die(mysql_error());
$numrows = mysql_num_rows($query);
if ($numrows == 1){
$errors[] = 'Item was added.';
$filename = "$item_id.jpg";
move_uploaded_file($_FILES['item_img']['temp_name'], "img/items/$filename");
mysql_close();