PHP has some default limits that do not work out of the box when you want to work with uploading very large files.
So there are a few configuration changes you have to make to the defaults that come with PHP. These are defined in you php.ini file.
The files location can be found with the
<?php phpinfo() ?> function. Just look for the location of the .ini file.
Changing this file will require rebooting the apache/nginx server as well.
You can also set them in your PHP script with the
ini_set method. This method is a little more flexible because you can tweak it at runtime
without needing to reboot your server. The PHP script below uses this approach.
Copy the PHP script below to a directory and place in an index.php file. Then boot up the script from the root of that directory with
php -S localhost:5000
You can then test uploading with curl from the command line, replacing your.jpg with a file you want to upload. The file_name parameter is what the PHP script will save the file as, on the server.
curl -X POST --data-binary @your.jpg http://localhost:5000/?file_name=my.jpg
And the PHP Script is
<?php ini_set("upload_max_filesize", "500M"); ini_set("post_max_size", "500M"); ini_set("max_input_time", 3600); ini_set("max_execution_time", 3600); ini_set("memory_limit","500M"); file_put_contents(($_GET["file_name"] ?? "img.jpg"), file_get_contents("php://input")); echo json_encode(["message" => "Upload complete!"]);