3

I am implementing in my system dropzone.js to upload files to the server or to dropbox depending on the size of the file.

And i also use sweet alerts for notifications.

When the file is uploaded to my server dropzone works correctly but when it is uploaded to dropbox does not return any results

test with files larger than 6 Mb

Demo here

and them the loading bar does not work properly

Dropzone.js

HTML:

<form id="cuadro" action="" class="dropzone">

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

JS:

<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

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 file enter image description here enter image description here

Wilfredo Aleman
  • 101
  • 2
  • 15
  • 1
    What exactly does “not return any results”? Your PHP script only seems to respond with either a status code 200, or a 400 in case of an error. What “results” are you expecting to appear where exactly now? – misorude Jul 10 '19 at 10:03
  • I need the system to return 200 if it has uploaded the file or 400 if it has not. but sometimes the file has been loaded correctly but does not return any results – Wilfredo Aleman Jul 10 '19 at 10:18
  • 1
    Meaning what, exactly? Does the client-side part just ”hang”, and not go into the `complete`handler at all? Something else? What are you observing in the browser dev tools network panel? – misorude Jul 10 '19 at 10:46
  • I have prepared a demo for you. you will find it in the text of the question – Wilfredo Aleman Jul 10 '19 at 11:08
  • 1
    Have you checked the `post_max_size` and `upload_file_maxsize` directives on php.ini? [reference](https://stackoverflow.com/a/2184541/7302869) – Diogo Sgrillo Jul 12 '19 at 09:16
  • @DiogoSgrillo yes i have, `allow_url_fopen On display_errors Off error_reporting E_ALL file_uploads On include_path .:/opt/alt/php72/usr/share/pear log_errors On mail.force_extra_parameters no value max_execution_time 10800 max_input_time 10800 memory_limit 128M open_basedir no value post_max_size 128M session.save_path /opt/alt/php72/var/lib/php/session short_open_tag On upload_max_filesize 1G` – Wilfredo Aleman Jul 12 '19 at 09:20
  • @DiogoSgrillo But that's not the problem. That works correctly. the problem occurs when I try to upload the file to dropbox – Wilfredo Aleman Jul 12 '19 at 09:22
  • 1
    I just tried to upload a file using your demo, and the script died exactly at 30s. Are you using FastCGI? Perhaps the idle_timeout is set to 30s – Diogo Sgrillo Jul 12 '19 at 10:45
  • I'm not using FastCGI, in fact I've never heard it before. How can I implement it? – Wilfredo Aleman Jul 12 '19 at 10:58

1 Answers1

2

I've tested your demo, and was able to upload a bigger than 6mb file now and then. Sometimes, while doing the upload, the script died exactly at 30s.

Thus, it seems that the logic of your code is ok, but there is some timeout occurring in your server. As you already pointed, the max_execution_time and max_input_time seems to be properly set (I'd double check with phpinfo();), but depending on the server you are running, you might have another places to check.

  • If it is running on Apache, check in the httpd.conf the TimeOut directive.
  • If you are using php-fpm, check in the www.conf the request_terminate_timeout directive.
  • If you are using nginx, check the fastcgi_read_timeout directive

reference

Diogo Sgrillo
  • 2,601
  • 1
  • 18
  • 28