首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dropzone.js和dropbox

Dropzone.js和dropbox
EN

Stack Overflow用户
提问于 2019-07-04 09:37:40
回答 1查看 584关注 0票数 3

我正在我的系统dropzone.js实现上传文件到服务器或dropbox,这取决于文件的大小。

我还使用甜警报作为通知。

当文件上载到我的服务器时,下拉区域正确地工作,但是当它上传到dropbox时不会返回任何结果

大于6MB的文件的测试

这里的演示

而且加载条不能正常工作。

Dropzone.js

HTML:

代码语言:javascript
复制
<form id="cuadro" action="" class="dropzone">

</form>
<p id="texto_carga" style="color: #009688; display:none">Espera mientras se procesa el archivo...</p> 

联署材料:

代码语言:javascript
复制
<script type="text/javascript">
     var errors = false;
     var Dropzone = new Dropzone("#cuadro", {
     url: "../utilidades/pruebasupload.php?id=<?=$personaId?>&codigo=<?=$codigo?>",
     acceptedFiles: ".EDF,.edf,.pdf,.PDF,.rar,.RAR,.jpg,.png,.gif",
     maxFiles: 1,
     error:function(){
       errors = true;
     },
     processing:function(){ 
        $('#texto_carga').show();
     },
     complete:function(){
        if(errors){
          swal({
             title: 'Error al cargar el achivo!',
             text: 'Ha ocurrido un error al intentar cargar el archivo. Póngase en contacto con el administrador del sistema',
             type: 'error',
             icon: 'error'
          });
          $('#texto_carga').hide();
        }else{
          swal({
             title: 'Carga completa!',
             text: 'Hemos cargado el archivo de la prueba exitosamente',
             type: 'success',
             icon: 'success'
          });  
          $('#texto_carga').hide();
        }
      }
   });
</script>

PHP pruebasupload.php

代码语言:javascript
复制
require_once "../terceros/dropbox/vendor/autoload.php";
require_once '../clases/servidor_archivos_controller.php';
require_once '../clases/conexion.php';

use Kunnu\Dropbox\Dropbox;
use Kunnu\Dropbox\DropboxApp;
use Kunnu\Dropbox\DropboxFile;

$conexion = new conexion;
$_servidor = new servidorArchivos;

$data = $_servidor->buscarConexion();
$dropboxKey = "";
$dropboxSecret = "";
$acessToken = "";
$appName= "";
$megas = "";

if(empty($data)){
    $megas = 200000;
}else{
    $dropboxKey = $data[0]['Keyapp'];
    $dropboxSecret = $data[0]['Secret'];
    $acessToken = $data[0]['Token'];
    $appName= $data[0]['Appname'];
    $megas = $data[0]['Megas'];
    $megas = ($megas * 1024) * 1024 ;
}
 
 
 
 
if($tama[0]>$megas){
    try{
     //upload file to dropbox
     $file = $dropbox->simpleUpload($tempFile,$nombredropbox, ['autorename' => true]);  
     //share a file
     $response = $dropbox->postToAPI("/sharing/create_shared_link_with_settings", ["path" => $nombredropbox, "settings" => ['requested_visibility' => 'public']]);
    $data = $response->getDecodedBody();
    $link = $data['url'];
    //save link to document in to DB
    $query = "insert into pruebas_archivos (Codigo,Archivo,Ubicacion)values('$savecodge','$nombredropbox','2')";
                $datos=  $conexion->NonQuery($query); 
                http_response_code(200);
             }catch(\EXCEPTION $e){
                ERROR('001',$E);
                http_response_code(400);
             }
        }else{
            $targetPath = "../public/pruebas/";  
            $targetFile =  $targetPath.$id ."_". $nombreCompleto;  //5
            move_uploaded_file($tempFile,$targetFile);
            //save the url into DB
            $query = "insert into pruebas_archivos (Codigo,Archivo,Ubicacion)values('$savecodge','$nombreCompleto','1')";
            $conexion->NonQuery($query); 
            http_response_code(200); 
      
        }
}        
        
    function error($numero,$texto){
    $ddf = fopen('error.log','a');
    fwrite($ddf,"[".date("r")."] Error $numero: $texto\r\n");
    fclose($ddf);
  }

PHP init文件

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-16 09:09:05

我已经测试了你的演示,并能够上传一个大于6mb的文件,不时。有时候,在上传的时候,脚本会在30岁左右就死掉了。

因此,您的代码的逻辑似乎是正常的,但是在您的服务器中出现了一些超时。正如您已经指出的,max_execution_timemax_input_time似乎被正确设置(我会再次检查phpinfo();),但取决于您正在运行的服务器,您可能还有其他地方需要检查。

  • 如果它在Apache上运行,请签入httpd.conf -- TimeOut指令。
  • 如果您正在使用php-fpm,请签入www.conf -- request_terminate_timeout指令。
  • 如果您正在使用nginx,请检查fastcgi_read_timeout指令。

参考文献

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56884997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档