简体   繁体   English

jQuery文件上传php数据库blueimp

[英]jquery file upload php database blueimp

I am working with this plugin, I was looking for a lot of information about it and I would like to help me. 我正在使用此插件,我一直在寻找有关它的大量信息,并希望对我有所帮助。 1) When more than 5000 files are passed the jsone is no longer generated With respect to this I was working to make a call by the ID of the database but I still do not get for example fotos.php? 1)当传递超过5000个文件时,不再生成jsone。关于此,我正在尝试通过数据库ID进行调用,但仍然无法获取例如fotos.php? Id = 1 and that only generates the json of that query 2) Update Update the data already in the database Id = 1,并且仅生成该查询的json。2)Update更新数据库中已存在的数据

This is my php file which is located /server/php/index.php 这是我的php文件,位于/server/php/index.php

class CustomUploadHandler extends UploadHandler {


protected function initialize() {
    $this->db = new mysqli(
        $this->options['db_host'],
        $this->options['db_user'],
        $this->options['db_pass'],
        $this->options['db_name']
    );
    parent::initialize();
    $this->db->close();
}

protected function handle_form_data($file, $index) {
    $file->title = @$_REQUEST['title'][$index];
    $file->description = @$_REQUEST['description'][$index];
    $file->padre = @$_REQUEST['padre'][$index];


}

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
                                      $index = null, $content_range = null) {
    $file = parent::handle_file_upload(
        $uploaded_file, $name, $size, $type, $error, $index, $content_range
    );
    if (empty($file->error)) {
        $sql = 'INSERT INTO `'.$this->options['db_table']
            .'` (`ruta_adjunto`, `id_documento`, `tipo_adjunto`, `nombre_adjunto`, `descripcion_adjunto`)'
            .' VALUES (?, ?, ?, ?, ?)';
        $query = $this->db->prepare($sql);
        $query->bind_param(
            'sisss',
            $file->name,
            $file->padre, //id_documento luego ver como traer el id
            $file->type,
            $file->title,
            $file->description
        );
        $query->execute();
        //echo json_encode($query->error);
        $file->id_adjunto = $this->db->insert_id;
    }
    return $file;
}


protected function set_additional_file_properties($file) {
    parent::set_additional_file_properties($file);
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
        $sql = 'SELECT `id_adjunto`, `id_documento`, `ruta_adjunto`, `nombre_adjunto`, `descripcion_adjunto` FROM `'
            .$this->options['db_table'].'` WHERE `ruta_adjunto`=?';
        $query = $this->db->prepare($sql);
        $query->bind_param('s', $file->name);
        $query->execute();
        $query->bind_result(
            $id_adjunto,
            $id_documento,
            $titulo_documento,
            $descripcion_documento
        );
        while ($query->fetch()) {
            $file->id = $id_adjunto;
            //$file->type = $type;
            $file->padre = $id_documento;
            $file->title = $titulo_documento;
            $file->description = $descripcion_documento;
        }
    }
}

public function delete($print_response = true) {
    $response = parent::delete(false);
    foreach ($response as $name => $deleted) {
        if ($deleted) {
            $sql = 'DELETE FROM `'
                .$this->options['db_table'].'` WHERE `ruta_adjunto`=?';
            $query = $this->db->prepare($sql);
            $query->bind_param('s', $name);
            $query->execute();
        }
    }
    return $this->generate_response($response, $print_response);
}

} }

$upload_handler = new CustomUploadHandler($options); $ upload_handler =新的CustomUploadHandler($ options);

So I have in the file upload.html 所以我在文件upload.html中

{% for (var i=0, file; file=o.files[i]; i++) { %}

<tr class="template-upload fade">
    <td>
        <span class="preview"></span>
    </td>
    <td>
    <label class="title">
        <span>Nombre:</span><br>
        <input name="title[]" class="form-control">
        </label>
    </td>
    <td>
    <label class="description">
        <span>Descripcion:</span><br>
        <input name="description[]" class="form-control">
        </label>
        <input name="padre[]" value="<?php echo $_GET['id'];?>" class="form-control">
    </td>
    <td>
        <p class="name">{%=file.name%}</p>
        <strong class="error text-danger"></strong>
    </td>
    <td>
        <p class="size">Procesando...</p>
        <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
    </td>
    <td>
        {% if (!i && !o.options.autoUpload) { %}
            <button class="btn btn-primary start" disabled>
                <i class="glyphicon glyphicon-upload"></i>
                <span>Comenzar</span>
            </button>
        {% } %}
        {% if (!i) { %}
            <button class="btn btn-warning cancel">
                <i class="glyphicon glyphicon-ban-circle"></i>
                <span>Cancelar</span>
            </button>
        {% } %}
    </td>
</tr>

{% } %} {%}%}

Here some reference 这里一些参考

Reference 1 参考1

Reference 2 参考2

While I do not think it is the best solution use the user_dirs of the file server /php/UploadHandler.php 虽然我认为这不是最佳解决方案,但请使用文件服务器/php/UploadHandler.php的user_dirs

On this line leave it like this 在这条线上像这样

'user_dirs' => true,

In the upload.html file 在upload.html文件中

session_start(); $_SESSION['father'] = $_GET['id'];

And in /server/php/index.php 并在/server/php/index.php中

protected function get_user_id() {
    @session_start();

    foreach( $_SESSION as $key=>$father ) {
        $username = $father;
    }
    return $username;

    #return session_id();
}

What it does is to pass the ID as a session and thus to see the assigned folder. 它的作用是将ID作为会话传递,从而查看分配的文件夹。

While I had a folder where all the files were together, make a small script that generates a folder with the ID number with the files 当我有一个将所有文件放在一起的文件夹时,制作一个小脚本,该脚本将生成一个带有文件ID号的文件夹

<?php

require_once ('../inc/conexion.php'); require_once('../inc/conexion.php');

$db = db::getInstance(); $ db = db :: getInstance();

$res = $db->query("SELECT * FROM adjuntos LIMIT 2000"); $ res = $ db-> query(“ SELECT * FROM adjuntos LIMIT 2000”);

$ruta = '../admin/server/php/files/'; $ ruta ='../admin/server/php/files/';

while($reg = $res->fetch_array()){ while($ reg = $ res-> fetch_array()){

if(file_exists($ruta.$reg['id_documento'])){
    $origen = '../pdfs/'.$reg['ruta_adjunto'];
    $destino = $ruta.$reg['id_documento'].'/'.$reg['ruta_adjunto'];
    if(!copy($origen, $destino)){
        echo 'error al copiar el archivo del id: '.$reg['id_documento'];
    }
}else{
    $carpeta = $ruta.$reg['id_documento'];
    if(!mkdir($carpeta, 0777, true)){
      echo 'Error al crear la CARPETA CON ID: '.$reg['id_documento'];
    }else{
        $origen = '../pdfs/'.$reg['ruta_adjunto'];
        $destino = $ruta.$reg['id_documento'].'/'.$reg['ruta_adjunto'];
        if(!copy($origen, $destino)){
            echo 'error al copiar el archivo del id: '.$reg['id_documento'];
        }
    }
}

} ?> }?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM