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

Asked

Viewed 277 times

-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");
  }
}
?>
  • What is the error message?

  • does not give any error, simply does not send

  • Then the message appears upload realizado com sucesso?

  • yes, but if I send a small file send normal, but if I send a file of some 3mb it simply won’t go

  • this on your computer or server?

  • This question probably solves your problem: https://answall.com/q/15573/3635 (answer: https://answall.com/a/15641/3635)

  • thanks friend .

Show 2 more comments

1 answer

3


Make a phpinfo.php file using the code below:

<?php phpinfo(); ?>

And open it in the browser. In the "Loaded Configuration File" part, the path to the configuration file used will appear, usually php.ini. Of course, if it’s 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 the posted data but also affects file uploading)

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

max_execution_time:(Maximum running time)

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

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

References: http://php.net/manual/en/ini.core.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.