Why can not I upload more than 2mb with this script?

-2
<form action="" method="post" enctype="multipart/form-data">
  <input type="file" name="fileUpload"/><br/>
  <button type="submit">Enviar</button>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"]==="POST"){
    $file = isset($_FILES["fileUpload"])?$_FILES["fileUpload"]:"";
    if($file["error"]){

    }

    $dirUploads = "uploads";
    if(!is_dir($dirUploads)){
        mkdir($dirUploads);
    }
   if (move_uploaded_file($file["tmp_name"],$dirUploads.DIRECTORY_SEPARATOR.$file["name"])){
       echo "upload realizado com sucesso"."<br>";

   }else{
       throw new Exception("Não foi possivel fazer o upload");
  }
}
?>
    
asked by anonymous 16.06.2018 / 20:48

1 answer

3

Make a phpinfo.php file using the code below:

<?php phpinfo(); ?>

And open it in your browser. In the "Loaded Configuration File" part, the path to the configuration file used, usually php.ini will appear. Of course, if it is not shared hosting and you have access to change it.

You can also create a php.ini file at the root of your project.

In php.ini, change the part:

upload_max_filesize: (maximum upload size)

post_max_size: (maximum size of posted data, but also affects file upload)

memory_limit: (maximum amount of memory, in bytes, that the script can allocate. This must be greater than "post_max_size")

max_execution_time: (Maximum execution time)

When loading large files, it is important not to leave a very short time, as errors may occur if you do not have time to send the entire file.

Also note if the user has access to write to the directory where the uploaded file will be saved.

References: link

    
16.06.2018 / 21:28