的print_r($ _ FILES);输出为空数Array()**。这意味着没有上传文件,但我上传了文件

时间:2017-03-28 10:01:40

标签: php mysql image-uploading

我正在尝试上传图片 上传图片的代码如下:

if (!isset($_POST['submit'])) {
    if (isset($_FILES['imageUpload'])) {

        // image upload
        $target_dir = "C:/wamp64/www/images/";
        $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);

        echo 'Your tmp location of img file  is ' . $_FILES['imageUpload']['tmp_name'] . '<br>';
        $imagetmp = addslashes(file_get_contents($_FILES['imageUpload']['tmp_name']));

        if (isset($_FILES['imageUpload'])) {
            if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
                echo "The file " . basename($_FILES["imageUpload"]["name"]) . " has been uploaded.";
            } else {
                echo "Sorry, there was an error uploading your file.";
            }
        }

        $image = basename($_FILES["imageUpload"]["name"], ".jpg");
        $imagename = addslashes($_FILES['imageUpload']['name']);
    }

    $query = "INSERT INTO `form_details` (firstname,secondname,location,designation,fileno,doa,doj,cardtype1,cardcolor,cardtype2,door1,door2,door3,door4,door5,door6,door7,door8,door9,door10,door11,door12,imagetmp,imagename) VALUES('$firstname','$secondname','$location','$designation','$fileno','$doa','$doj','$cardtype1','$cardcolor','$cardtype2','$door1','$door2','$door3','$door4','$door5','$door6','$door7','$door8','$door9','$door10','$door11','$door12','$imagetmp','$imagename')"; //query
    if (mysqli_query($connect, $query)) { //check query executed or not
        echo 'inserted' . '<br>';
    } else {
        echo "problem occur" . mysqli_error($connect);
    }
} else {
    echo "form values are required";
}
  

Undefined index: imageUpload in
  file_get_contents(): Filename cannot be empty    是两个错误。

我尝试了isset,它没有用。 print_r($_FILES);输出为空Array ( )。这意味着没有上传文件,但我已经上传了该文件。

我无法将图片添加到指定位置

我能够成功执行查询,但不会将图片上传到数据库。

我的照片代码

<div class="form-inline">
  <label for="Passportcopy">Passport Copy</label>
  <input type="file" class="form-control"  name="imageUpload"/>
</div>

1 个答案:

答案 0 :(得分:0)

尝试删除第一个!

中的isset
if(isset($_POST['submit'])){
//...other codes
}