Problems uploading PHP

0

I have an upload system where the client publishes PDF files on the site. Files lower than 10MB all happen well, but when the file is over 10MB, the system stays at 92% and does not upload. See:

Icontactedtheserverandtheysaidthelimitis128MB.Iwasindoubt,becauseifthesystemuploadsfileslessthan10MB,whydoesitabove10MBitstopsat92%anddoesitgeneratenoerrorandnoerrorlogsontheserver?Seebelowthecode:

HTML

<formaction="#" method="post" enctype="multipart/form-data">                       

                      <div class="form-group">
                        <label for="titulo">Título: </label>
                        <input id="titulo" class="form-control" name="Titulo" placeholder="" type="text">
                      </div>
                      <div class="form-group">
                       <label for="periodo">Período:</label>
                            <div class="input-group col-md-3">                        
                              <input id="periodo" class="form-control" name="PeriodoInicio" placeholder="" type="text" data-inputmask="'mask' : '99/99/9999'">
                              <span class="input-group-addon">à</span> 
                              <input id="periodo" class="form-control" name="PeriodoFinal" placeholder="" type="text" data-inputmask="'mask' : '99/99/9999'">
                          </div>
                      </div>
                      <div class="row">
                          <div class="form-group">
                            <div class="col-md-12">
                             <label for="ano">Ano:</label>
                           </div>
                            <div class="col-md-3">
                            <input id="ano" class="form-control" name="AnoEdicao" placeholder="Ex.: <?php echo date("Y"); ?>" type="text" maxlength="4" data-inputmask="'mask' : '9999'">
                          </div>
                          </div>
                      </div>
                      <div class="form-group" style="margin-top: 10px">
                       <label for="arquivo">Arquivo:</label>
                        <input type="file" id="arquivo" name="Arquivo" class="form-control" style="cursor: pointer">
                      </div>
                      <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-12">
                                <div class="progress progress-striped active">
                                        <div class="progress-bar" style="width: 0%">
                                        </div>
                                </div>
                        </div>
                    </div> 
                    <div align="center">
                        <button id="send" type="submit" class="btn btn-primary"><i class="fa fa-floppy-o fa-lg" aria-hidden="true"></i> Salvar</button>
                      </div>
                    </form>

<script>
    $(document).on('submit', 'form', function (e) {
            e.preventDefault();
            //Receber os dados
            $form = $(this);        
            var formdata = new FormData($form[0]);

            //Criar a conexao com o servidor
            var request = new XMLHttpRequest();

            //Progresso do Upload
            request.upload.addEventListener('progress', function (e) {
                    var percent = Math.round(e.loaded / e.total * 100);
                    $form.find('.progress-bar').width(percent + '%').html(percent + '%');
            });

            //Upload completo limpar a barra de progresso
            request.addEventListener('load', function(e){
            $form.find('.progress-bar').addClass('progress-bar-success').html('upload completo...');
            //Atualizar a página após o upload completo
            setTimeout("window.open(self.location, '_self');", 1000);
            });

            //Arquivo responsável em fazer o upload da imagem
            request.open('post', 'processar-cadastro-edicoes.php');
            request.send(formdata);
            console.log(formdata);
    });
</script>

PHP

public function cadastrarEdicoes($arquivo,$temp,$titulo,$periodoInicio,$periodoFinal,$anoEdicao){

      $sqlVerificar = mysqli_query($this->conexao,"SELECT * FROM pf_edicoes WHERE Titulo = '".$titulo."' AND PeriodoInicio = '".mysqli_real_escape_string($this->conexao,$periodoInicio)."' AND PeriodoFinal = '".mysqli_real_escape_string($this->conexao,$periodoFinal)."' AND anoEdicao = '".mysqli_real_escape_string($this->conexao,$anoEdicao)."';");

      if(mysqli_num_rows($sqlVerificar) > 0){
           $_SESSION["CadastroExistente"] = time() + 3; // Verifica se o arquivo e o período já está cadastrado      
      }else{
        $extensao = pathinfo($arquivo, PATHINFO_EXTENSION);

           if($extensao != "pdf"){
              $_SESSION["ErroExtensao"] = time() + 3; // Verifica se a extensão é pdf
           }else{   
              $antigo = umask(0);
              $criarDiretorio = mkdir("../../arquivos/".$anoEdicao,0777); 
              umask($antigo);
              $diretorio = "../../arquivos/".$anoEdicao;

              list($nomeArquivo,$extensaoArquivo) = explode(".".$extensao,$arquivo);
              $codArquivo = md5(date("d-m-Y H:i:s").$nomeArquivo).".".$extensao;

                if(move_uploaded_file($temp,$diretorio."/".$codArquivo)){
                   $cadArquivo = "arquivos/".$anoEdicao."/".$codArquivo;
                   $sqlCadastrar = mysqli_query($this->conexao,"INSERT INTO pf_edicoes VALUES(null,'0','".mysqli_real_escape_string($this->conexao,$titulo)."','".mysqli_real_escape_string($this->conexao,$periodoInicio)."','".mysqli_real_escape_string($this->conexao,$periodoFinal)."','".mysqli_real_escape_string($this->conexao,$cadArquivo)."','".mysqli_real_escape_string($this->conexao,$anoEdicao)."')");

                   if(mysqli_affected_rows($this->conexao) > 0){

                      $idEdicao = mysqli_insert_id($this->conexao);
                      mysqli_query($this->conexao,"UPDATE pf_edicoes SET IdCodEdicoes = '".md5(strrev($idEdicao))."' WHERE IdEdicoes = '".$idEdicao."';");

                      $_SESSION["Sucesso"] = time() + 3;
                      return "<script>window.location.href='cadastrar-edicoes.php';</script>";
                   }else{
                      $_SESSION["ErroCadastro"] = time() + 3; // Erro no cadastro
                   }   

                }else{
                   $_SESSION["ErroUpload"] = time() + 3; // Erro no uplado
                } 
            }
        }
    } 

I honestly do not know where the error is. Whether it's on our side or the server side.

PHP configuration on the server:

    
asked by anonymous 21.02.2018 / 15:30

1 answer

1

The block can be in post_max_size or upload_max_filesize , a very important detail, after editing PHP.INI or PHPRC it is necessary to restart the HTTP server (and / or fastcgi if is using something like some reverse proxy).

However the Apache also blocks to limit the size of payload .

Maybe Apache or some .htaccess is being blocked by LimitRequestBody or else:

  • LimitRequestFields
  • LimitRequestFieldSize
  • LimitRequestLine

Or you can have any other problem that just looking in the browser console to know which fault has occurred, and may even be a failure on your local network.

If it is a failure in the local network, something that I have suffered several times, then there is no way to solve with programming or with servers, maybe the best totally change approach , in case I recommend even to improve the response time on the server when there are multiple sessions is to partition the upload using the API:

However from scratch I understand that it is something complex, which will require better knowledge of HTTP and better knowledge of the api and behaviors between different browsers, as it seems that you already use jQuery so I recommend a library ready to link

The link explains how to partition, for example:

$('#fileupload').fileupload({maxChunkSize: 1000000}) //Divide de um 1 MB por vez
    .on('fileuploadchunksend', function (e, data) {})
    .on('fileuploadchunkdone', function (e, data) {})
    .on('fileuploadchunkfail', function (e, data) {})
    .on('fileuploadchunkalways', function (e, data) {});
    
21.02.2018 / 16:32