在Fine Uploader中重定向文件上载请求

时间:2016-06-07 18:07:11

标签: javascript php file-upload jquery-file-upload

我使用Fine Uploader上传多个文件。 它工作正常。 但我想稍微改变一下。

我有一个文件名upload.php,我在其中编写了一个文件上传脚本在数据库中。 我只想在点击上传按钮后,请求将转到我的upload.php文件,文件将相应上传。

我如何实现这一目标?

的index.php

<script type="text/template" id="qq-template-manual-trigger">

 <div class="buttons">
    <div class="qq-upload-button-selector qq-upload-button">
         <div>Select files</div>
    </div>

<button type="button" id="trigger-upload" class="btn btn-primary">
      <i class="icon-upload icon-white"></i> Upload
</button>

</div>
 </script>

的Javascript

   <script>
        var manualUploader = new qq.FineUploader({
            element: document.getElementById('fine-uploader-manual-trigger'),
            template: 'qq-template-manual-trigger',
            request: {
                endpoint: '/server/upload.php'
            },
            thumbnails: {
                placeholders: {
                    waitingPath: '/source/placeholders/waiting-generic.png',
                    notAvailablePath: '/source/placeholders/not_available-generic.png'
                }
            },
            autoUpload: false,
            debug: true
        });

        qq(document.getElementById("trigger-upload")).attach("click", function() {
            manualUploader.uploadStoredFiles();
        });
    </script>

upload.php的

<?php

require_once './include/db_connection.php';

if(!empty($_FILES)){

    $targetDir = "upload/";
    $fileName = $_FILES['file']['name'];
    $targetFile = $targetDir.$fileName;

   if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile))

   {
        //insert file information into db table
 $sql = mysqli_query($link,"INSERT INTO files (file_name, uploaded) VALUES('".$fileName."','".date("Y-m-d H:i:s")."')");
    }
    else
    {
        echo 'Query not working';
    }

}

0 个答案:

没有答案