无法使用Dropzone插入照片

时间:2015-11-21 12:35:47

标签: php mysql dropzone.js

我正在尝试使用dropzone.js插入照片,但它无法正常工作。我检查了我的phpmyadmin它显示零照片。以下是我的上传代码。

<?php

require_once("db.php")

if(!empty($_FILES)){
    $caption = $_POST['caption'];
    $album = $_POST['album'];
    $photo = $_FILES['photo']['name'];
    $temp = $_FILES['photo']['tmp_name']; //temporary file
    $path = "photos/".$photo;


//check if a caption has been entered or photo chosen, if empty display an error messages
if(empty($caption)){
    $captionError = "Caption can not be empty";
}

if(empty($photo)){
    $photoError = "You must select a photo to upload";
}

//no errors, insert into the database
if(move_uploaded_file($temp, $path)){
    $sql = "INSERT INTO photos(photoPath, photoName, eventID) VALUES('$path', '$caption', '$album')";
    //$query = mysqli_query($connect, $sql);
    $rs = $db->prepare($sql);

    $rs->execute();


if($rs){
    $photoUploadSuccess = "Photo uploaded successfully";
    header("location: http://localhost:8080/CaseProject/uploadindex.php");
    exit;
}else {
    $photoUploadError = "Photo not uploaded, try again later";
}

}
?>

这是我的HTML代码:

<form accept-charset="UTF-8" role="form" action="upload.php" class="dropzone">
            </form>
            <script type="text/javascript">
            $(document).ready(function () {
                Dropzone.options.myAwesomeDropzone = {
                paramName: "file", // The name that will be used to transfer the file
                maxFilesize: 20, // MB
                dictDefaultMessage: "Drop files here or click to upload",
                parallelUploads: 1,
                accept: function (file, done) {
                    if (file.name == "justinbieber.jpg") {
                        done("Naha, you don't.");
                    }
                    else {
                        done();
                    }
                }
            };
            </script>

我尝试搜索其他一些教程,但仍无效。

有人可以帮我解决这个问题吗。

0 个答案:

没有答案