-3

when Try to upload files less 2mb everything goes fine when it be more 2Mb I get "cant not upload a file"

<!DOCTYPE html>
<head> <title> My website  </title> 
</head> <body bgcolor = "#99CC99">
 <?php $directory = "userfiles/";
 $File_name = $_FILES["userfile"]["name"]; 
 $Type = $_FILES["userfile"]["type"] ;
 $Size = ($_FILES["userfile"]["size"] / 1024); 
 $File_temp_name = $_FILES["userfile"]["tmp_name"];
 if($Size<= 0){ die('cant not upload a file '); } 
 if (file_exists($directory . " / " . $_FILES["userfile"]["name"])) { die($_FILES["userfile"]["name"] . " already exists. "); }
 if(is_uploaded_file($_FILES["userfile"]["tmp_name"])){ if(!move_uploaded_file($File_temp_name,$directory."/".$File_name))
 { die('cant not file'.$File_name); } } else { die('attack on file'); } echo $File_name . " is sucessfully uploaded " . " <br/> " ; 
echo "file size : " .$Size. " <br/> "; 
echo"type :".$Type." <br/> "; ?> </body>
 </html>

when upload file 2mb or more I get "cant not upload a file"

  • 1
    tried increasing the max upload size in php ini? – Rotimi Jul 11 '20 at 15:32
  • 1
    FYI please validate the file type before uploading. Your script allows any type of file to be uploaded and that is dangerous – Rotimi Jul 11 '20 at 15:33
  • What is the value of [`$_FILES["userfile"]["error"]`](https://www.php.net/manual/en/features.file-upload.errors.php)? – Progman Jul 11 '20 at 15:41
  • 1
    Does this answer your question? [Change the maximum upload file size](https://stackoverflow.com/questions/2184513/change-the-maximum-upload-file-size) – Onimusha Jul 11 '20 at 15:46
  • thanks tried increasing the max upload size in php ini that solve worked for me it was 2mb – abdelrhman khaled Jul 11 '20 at 15:56

2 Answers2

1

This is basically a problem with the default configuration set in php.ini file

By default, PHP file upload size is set to maximum 2MB file in php.ini file

To increase file upload size in PHP, update the upload_max_filesize and post_max_size in your php.ini file

upload_max_filesize = 64M
post_max_size = 32M

You can set the value based on your requirements.

In addition, you can also set the maximum number of files allowed to be uploaded in a single request using the max_file_uploads.

max_file_uploads = 30

After modifying php.ini file, make sure you restart your server.

For confirmation, whether your changes are done or not. You can create a test file inside your project folder.

Create test.php and write following code:

<?php
   phpinfo();
?>

Save the file and open in browser. It will look something like this:

test.php file

Search for upload_max_filesize and post_max_size in this, it should reflect the new values.

Ankit Jindal
  • 3,672
  • 3
  • 25
  • 37
0

Most probably you reached upload_max_filesize within your PHP config, change the value for higher in your php.ini file, and don't forget to restart the Apache server.

TIP: you can check current vaalues and location of the path of used php.ini using this PHP script:

<?php
   phpinfo();

phpinfo() docs

biesior
  • 55,576
  • 10
  • 125
  • 182
  • I really think we should discourage this "How do I do this?" type of questions on SO by experienced members not posting answers that already available in abundance on the same site. – Onimusha Jul 11 '20 at 15:47