簡體   English   中英

jQuery文件上傳php數據庫blueimp

[英]jquery file upload php database blueimp

我正在使用此插件,我一直在尋找有關它的大量信息,並希望對我有所幫助。 1)當傳遞超過5000個文件時,不再生成jsone。關於此,我正在嘗試通過數據庫ID進行調用,但仍然無法獲取例如fotos.php? Id = 1,並且僅生成該查詢的json。2)Update更新數據庫中已存在的數據

這是我的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 =新的CustomUploadHandler($ options);

所以我在文件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>

{%}%}

這里一些參考

參考1

參考2

雖然我認為這不是最佳解決方案,但請使用文件服務器/php/UploadHandler.php的user_dirs

在這條線上像這樣

'user_dirs' => true,

在upload.html文件中

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

並在/server/php/index.php中

protected function get_user_id() {
    @session_start();

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

    #return session_id();
}

它的作用是將ID作為會話傳遞,從而查看分配的文件夾。

當我有一個將所有文件放在一起的文件夾時,制作一個小腳本,該腳本將生成一個帶有文件ID號的文件夾

<?php

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

$ db = db :: getInstance();

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

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

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