How to Change the Maximum Upload File Size in PHP: A Complete Guide

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: "File too large" — a familiar pain?

\n\n

Have you ever tried to upload a high-resolution photo, a video for your blog, or a ZIP archive with documents to a website, only to see the ruthless error: "The maximum upload file size has been exceeded"? If so — you are not alone. On Stack Overflow, the question "Change the maximum upload file size" has gathered tens of thousands of views, meaning hundreds of thousands of developers (from beginners to pros) have hit this wall.

\n\n

On the educational portal PythonLib, we teach you not just to copy code, but to understand how everything works from the inside. Today, we'll break down, in simple terms with real examples, how to change the upload limit in PHP. You'll learn where the settings are hidden, why they don't always work, and how to avoid the most common pitfalls. Let's go!

\n\n

Why doesn't PHP allow uploading large files?

\n\n

By default, PHP is quite modest. It allows uploading files of only 2 megabytes (and even less in some older versions). This is done for security reasons: imagine an attacker uploading a gigabyte-sized file to your server and crashing the site. But for legitimate tasks (like uploading a portfolio or a video tutorial), this is catastrophically small.

\n\n

Where does the limit come from? The answer is from three main directives in the PHP configuration:

\n\n
    \n
  • upload_max_filesize — the maximum size of a single uploaded file.
  • \n
  • post_max_size — the maximum size of all data sent via the POST method (including files and form text fields).
  • \n
  • max_execution_time — the time PHP can spend executing a script (uploading a large file can take minutes).
  • \n
\n\n

If you only increase upload_max_filesize but forget about post_max_size, the upload will still fail with an error. It's like trying to stuff an elephant into a trunk when the trunk is smaller than the elephant. Or when you have a big box (the file), but the mailbox slot (post_max_size) is too narrow.

\n\n

Where do PHP settings live? Three paths to success

\n\n

You have three ways to change the maximum upload file size. Which one to choose depends on your hosting and access level. Let's break down each one.

\n\n

Method 1: Editing php.ini (the gold standard)

\n\n

The php.ini file is the main "control panel" for PHP. If you have access to the server (VPS, dedicated server, or local computer), this is the most reliable method.

\n\n

Find your php.ini. It is usually located in:

\n
    \n
  • Linux: /etc/php/8.x/apache2/php.ini or /etc/php/8.x/cli/php.ini
  • \n
  • Windows: C:\\xampp\\php\\php.ini (for XAMPP) or C:\\wamp64\\bin\\php\\php8.x\\php.ini
  • \n
\n\n

Open the file and find (or add) the following lines:

\n\n
; Maximum size of a single file (now 50 MB)\nupload_max_filesize = 50M\n\n; Maximum size of all POST data (must be greater than or equal to upload_max_filesize)\npost_max_size = 64M\n\n; Maximum script execution time in seconds (increase to 300 for large files)\nmax_execution_time = 300\n\n; Maximum time to receive data (recommended to set at least 5 minutes)\nmax_input_time = 300\n\n; Memory per script (if the file is large, increase to 128M or 256M)\nmemory_limit = 128M
\n\n

After making changes, be sure to restart the web server:

\n
sudo systemctl restart apache2   # for Apache\nsudo systemctl restart nginx     # for Nginx
\n\n

Done! Now your site can accept files up to 50 MB. But remember: post_max_size should always be a few megabytes larger than upload_max_filesize to leave room for the form's service headers.

\n\n

Method 2: The magic of .htaccess (for shar

Blogs

Book Recommendations