0

我正在尝试将图像上传到服务器,然后获取该图像名称并将其插入 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')"; 
4

1 回答 1

4

您需要在<form>标签中包含以下内容:

enctype="multipart/form-data"

所以它会变成:

<form name="addItem" method="post" action="add-new-item.php" enctype="multipart/form-data">   

在这里记录得很好-请参阅第一页底部的注释...

于 2012-05-03T13:55:47.690 回答