Script Alert does not work

0

I have a file upload code that works perfectly, but the alert in the else condition is not working just the IF alert.

Follow the code:

if(isset($_FILES['allfiles'])){//verifica o input file, caso estiver setado irá preparar as variaveis e caso o arquivo seja maior que 15mb irá mostrar erro.
   $errors= array();
   $file_name = $_FILES['allfiles']['name'];
   $namefile = $_POST ['allfiles'];
   $file_size = $_FILES['allfiles']['size'];
   $file_tmp = $_FILES['allfiles']['tmp_name'];
   $file_type= $_FILES['allfiles']['type'];
   $ext = pathinfo($file_name, PATHINFO_EXTENSION);
   $pasta1 = $_POST ['pasta1'];
   $pasta2 = $_POST ['pasta2'];
   if($file_size > 15097152){
      $errors[]='O arquivo nao pode exceder 15mb';
   } 


   if(empty($errors)==true){//caso não haja erro irá mover o arquivo para o diretório selecionado.
    if (empty ($namefile)==true){
        if (empty ($pasta1)==false){
            move_uploaded_file($file_tmp,"pasta/".$ID."/pasta1/".$file_name);
        }
        if (empty ($pasta2) ==false){
            move_uploaded_file($file_tmp,"pasta/".$ID."/pasta2/".$file_name);
        }
    }
    if (empty ($namefile)==false){
        if (empty ($pasta1)==false){
            move_uploaded_file($file_tmp,"pasta/".$ID."/pasta1/".$file_name);
            rename ("pasta/".$ID."/pasta1/".$file_name, "pasta/".$ID."/pasta1/".$namefile.".".$ext);
        }
        if (empty ($pasta2) ==false){
            move_uploaded_file($file_tmp,"pasta/".$ID."/pasta2/".$file_name);
            rename ("pasta/".$ID."/pasta2/".$file_name, "pasta/".$ID."/pasta2/".$namefile.".".$ext);
        }
    }
   echo "<script>alert('Arquivo enviado com sucesso!')</script>";
   }else{
   echo "<script>alert('Arquivo deve ser menor que 15mb!')</script>";
   }
}

OBS : I already checked if the problem was the $ errors variable, but even putting it in the $ IF file_size still does not work, I believe there is some conflict in php. I've already tested the code on another blank page and it still did not work, the only thing that happens when I try to upload a file larger than 15mb is a reload on the page, which I do not understand so far as I have no reference to a refresh on code. Does anyone have any idea what might be causing this problem?

    
asked by anonymous 11.10.2017 / 18:43

1 answer

1

When the page loads or loads after uploading a very large file, you should check to see if the POST request body limit and file size limit for uploading in PHP is not too low. You can check these values in the php.ini file:

post_max_size : link

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
post_max_size = 20M

upload_max_filesize : link

; Maximum allowed size for uploaded files.
upload_max_filesize = 20M

Remembering that you need to put the "M" of megabytes, otherwise the values will be read as bytes. Also note that post_max_size should never be less than upload_max_filesize , and if you plan to upload more than one file at a time, for example 3 20mb files, post_max_size would need to be 60mb.

    
11.10.2017 / 19:48