我正在尝试将图像上传到服务器,然后获取该图像名称并将其插入 mysql 数据库。在我进入数据库位之前,上传不起作用。我已将其范围缩小到 $_FILES 数组中没有数据的事实,当我回显 $imageFileName 时它是空白的。
这是我的表格的一部分:
<form name="addItem" method="post" action="add-new-item.php">
<input name="name" placeholder="Portfolio Item Name" type="text" id="itemName"/><br />
<input type="file" name="imageName" id="imageName" /><br />
</form>
脚本,它是表单所在页面的一部分:
$target = "images/";
$target = $target . basename( $_FILES['imageName']['name']);
$imageFileName=($_FILES['imageName']['name']);
if(move_uploaded_file($_FILES['imageName']['tmp_name'], $target)){
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}else {
echo "Sorry, there was a problem uploading your file.";
}
$query1="INSERT INTO portfolio_items (item_name,full_size_image) VALUES('$itemName','$itemImage')";