dongweng6241 2015-10-08 09:26
浏览 19

Dropzone上传图像并将所有图像序列化为一个要保存的数据

This is my function of inserting the images using dropzone but everytime I upload image it will insert a new id again it means new row..what I want is to upload all images in one row only and serialize all images.

<?php
if(!empty($_FILES)){

    include 'connection.php';

    $id = $_POST['id'];

    $targetDir = "uploads/";
    $fileName = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
    $img = $_FILES['file']['name'];
    $img_name = $id . "_" . uniqid() . "_" . ($_POST['default_pic'] == $img ? "1" : "0") . "." . $fileName;
    $targetFile = $targetDir.basename($img_name);
    if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){

        $new_data = array("cover" => ($_POST['default_pic'] == $img ? "1" : "0"), "img" => $img_name); 
        $new_array[] = $new_data;

        $data_serialize = serialize($new_array);
        //insert file information into db table
        $conn->query("INSERT INTO files (file_name, uploaded) VALUES('".$data_serialize."','".date("Y-m-d H:i:s")."')");

    }

}
?>

the use of my array there is to customize the name of image..and put them in one variable via functions serialize.

$new_data = array("cover" => ($_POST['default_pic'] == $img ? "1" : "0"), "img" => $img_name); 
$new_array[] = $new_data;
  • 写回答

1条回答 默认 最新

  • down101102 2015-10-09 06:24
    关注

    Dropzone allows you to set "uploadMultiple" parameter.

    http://www.dropzonejs.com/#config-uploadMultiple

    When this is used, Dropzone will send all files in a single HTTP request, and you need to handle them on the backend side (PHP in your case). You should be able to see the format if you var_dump your $_FILES

    <script type="text/javascript">
        $(function() {
            var myDropzone = new Dropzone("#dz", {
                uploadMultiple: true
            });
        });
    </script>
    

    and of course the HTML ...

    <form id="dz" 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端