...
See the new Filestack Workflows 2.0 in action with our sales engineer. Book a Walkthrough
We are aware of the recently disclosed PHP2Shell vulnerabilities (CVE-2026-109618 and CVE-2026-109619) and can confirm Filestack is not impacted by these vulnerabilities.

PHP File Upload, Secure and Built for Large Files

Add PHP file upload to any app with the Filestack PHP SDK. Files go straight to cloud storage, at any php.ini setting.

$ composer require filestack/filestack-php
upload.php
<?php
require 'vendor/autoload.php';

use Filestack\FilestackClient;

$client = new FilestackClient('YOUR_API_KEY');
$filelink = $client->upload('/path/to/report.pdf');
echo $filelink->url();
Output
https://cdn.filestackcontent.com/HANDLE

PHP File Upload at a Glance

PHP file upload uses an HTML form with enctype="multipart/form-data", the $_FILES array and move_uploaded_file(), within the upload_max_filesize and post_max_size settings in php.ini. Filestack sends files from the browser straight to cloud storage, so upload size follows your plan instead of php.ini, and its PHP SDK uploads and transforms files in a few lines.

Two Ways to Handle a File Upload in PHP

Native PHP script

  1. Multipart form Posts to upload.php
  2. $_FILES Within the php.ini limits
  3. Your disk After move_uploaded_file()

Filestack

  1. Picker or SDK Browser or server path
  2. Cloud storage Filestack or your S3
  3. Handle in PHP Saved with the record
Package
filestack/filestack-php on Composer, PSR-4 autoloaded
PHP version
PHP 8.3 or later
Upload from
A path on your server, or the browser with File Picker
php.ini
Browser uploads work at your current php.ini settings
Storage
Filestack storage, or your own Amazon S3, Google Cloud Storage or Azure container
File size
Limits depend on plan. See pricing
Getting started
Free plan with an API key. Compare plans
Frameworks
Laravel, Symfony and plain PHP, plus a WordPress plugin

How PHP File Upload Works With the Native Script

To upload a file in PHP, post a multipart/form-data form to a PHP file upload script that checks $_FILES and calls move_uploaded_file(). In PHP, upload a file to a server outside the web root, under a random name, after checking its type by content.


  1. The form posts with enctype="multipart/form-data", so PHP receives the file's bytes in $_FILES.


  2. Upload a file in PHP in five checks: the error code, the size, the real MIME type from finfo, a random file name, and a folder outside the web root.


  3. In PHP, upload multiple files by naming the input photos[] and adding multiple. PHP groups the files under one key, and each file gets the same size and finfo checks as the single-file script.

form.html
<form action="upload.php" method="post" enctype="multipart/form-data">
  <label for="document">Document</label>
  <input type="file" id="document" name="document" required>
  <button type="submit">Upload</button>
</form>
upload.php
<?php
$file = $_FILES['document'] ?? null;
if (!$file || $file['error'] !== UPLOAD_ERR_OK) {
  exit('Upload error');
}
if ($file['size'] > 5 * 1024 * 1024) {
  exit('Files up to 5 MB');
}
$types = ['image/jpeg' => 'jpg', 'image/png' => 'png', 'application/pdf' => 'pdf'];
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($file['tmp_name']);
if (!isset($types[$mime])) {
  exit('JPG, PNG or PDF files');
}
// /var/app/uploads sits outside the web root
$name = bin2hex(random_bytes(16)) . '.' . $types[$mime];
move_uploaded_file($file['tmp_name'], '/var/app/uploads/' . $name);
multiple.php
<?php
// <input type="file" name="photos[]" multiple>
foreach ($_FILES['photos']['tmp_name'] as $i => $tmp) {
  if ($_FILES['photos']['error'][$i] !== UPLOAD_ERR_OK) {
    continue;
  }
  // run the size and finfo checks from upload.php here
  $name = bin2hex(random_bytes(16));
  move_uploaded_file($tmp, '/var/app/uploads/' . $name);
}

PHP Upload Error Codes

Constant Value Meaning
UPLOAD_ERR_OK 0 The file uploaded successfully
UPLOAD_ERR_INI_SIZE 1 The file is larger than upload_max_filesize
UPLOAD_ERR_FORM_SIZE 2 The file is larger than the form's MAX_FILE_SIZE
UPLOAD_ERR_PARTIAL 3 Part of the file arrived
UPLOAD_ERR_NO_FILE 4 The form sent the field with no file chosen
UPLOAD_ERR_NO_TMP_DIR 6 PHP has no temporary folder configured
UPLOAD_ERR_CANT_WRITE 7 PHP could not write the file to disk
UPLOAD_ERR_EXTENSION 8 A PHP extension stopped the upload

PHP Upload Limits in php.ini, and How to Raise Them

To increase the file upload size limit in PHP, raise upload_max_filesize and post_max_size in php.ini, your PHP-FPM pool or .htaccess, then restart PHP. Five directives set the limits.

Each Upload Must Fit Every Limit
Your web serverIts own request body limit
post_max_size The whole request, all files plus fields
upload_max_filesize Each single file
Directive What it controls Where to change it
upload_max_filesize The largest single file. Default 2M php.ini, PHP-FPM pool, .htaccess
post_max_size The whole request, all files plus fields. Default 8M; set it above upload_max_filesize php.ini, PHP-FPM pool, .htaccess
max_file_uploads Files per request. Default 20 php.ini, PHP-FPM pool, .htaccess
max_input_time Seconds PHP spends reading the request php.ini, PHP-FPM pool, .htaccess
memory_limit Memory per script, for code that processes the file php.ini, PHP-FPM pool, .htaccess, ini_set()
  1. ini_get() prints the values PHP is running with. Upload size settings apply per directory, so set them in config files rather than with ini_set().

  2. With File Picker, files travel from the browser to storage, so upload size follows your Filestack plan instead of php.ini. Large files use multipart uploads with resume.

    Adaptive Intelligent Ingestion runs on paid plans. See plan limits.

limits.php
<?php
$keys = ['upload_max_filesize', 'post_max_size', 'max_file_uploads'];
foreach ($keys as $key) {
  echo $key . ' = ' . ini_get($key) . PHP_EOL;
}
php.ini
upload_max_filesize = 64M
post_max_size = 72M
max_file_uploads = 20
picker.html
<script src="https://static.filestackapi.com/filestack-js/4.x.x/filestack.min.js"></script>
<script>
  filestack.init('YOUR_API_KEY').picker({
    onUploadDone: (res) => console.log(res.filesUploaded[0].handle),
  }).open();
</script>

Upload Files With the Filestack PHP SDK

The easiest way to handle file uploads in a PHP app is the Filestack PHP SDK: install it with Composer, then call $client->upload(). It returns a Filelink you can transform and store.

  1. Install the SDK with Composer; it needs PHP 8.3 or later. upload() then stores a file from a server path and returns a Filelink with its handle and CDN URL.

  2. For PHP image upload, chain resize() and save() to store a resized copy, or resize on delivery through the CDN URL.

  3. Intelligent Ingestion uploads large files in adaptive chunks that resume. It runs on paid plans, and Filestack support turns it on for your API key.

  4. Wrap uploads in a try block and catch FilestackException to log the API message and retry.

  5. File Picker uploads from the browser and writes the handle into a hidden field. PHP receives the handle with the form and saves it.

$ composer require filestack/filestack-php
upload.php
<?php
require 'vendor/autoload.php';

use Filestack\FilestackClient;

$client = new FilestackClient('YOUR_API_KEY');
$filelink = $client->upload('/path/to/report.pdf');

echo $filelink->handle . PHP_EOL;
echo $filelink->url();
resize.php
$filelink = $client->upload('/path/to/photo.jpg');

// Store a 400 x 400 copy as a new file
$thumbUrl = $filelink->resize(400, 400)->save()->url();

// Or resize on delivery through the CDN URL
$cdnUrl = 'https://cdn.filestackcontent.com/resize=width:400/' . $filelink->handle;
large-file.php
<?php
$filelink = $client->upload('/path/to/video.mp4', [
  'intelligent' => true,
]);
errors.php
<?php
use Filestack\FilestackException;

try {
  $filelink = $client->upload('/path/to/file.pdf');
} catch (FilestackException $e) {
  error_log('Filestack: ' . $e->getMessage());
}
save.php
<?php
// The picker wrote the handle into <input type="hidden" name="file_handle">
$handle = preg_replace('/[^A-Za-z0-9]/', '', $_POST['file_handle'] ?? '');
$url = 'https://cdn.filestackcontent.com/' . $handle;

// Save $handle and $url with the record they belong to

Secure PHP File Uploads

Block malicious files during upload with eight checks: type by content, size, random names, storage outside the web root, virus scanning, signed requests, domain allow-lists and an event log. Read more about secure uploads.

  • Validate type by content

    finfo reads the real MIME type. File Picker checks magic bytes with acceptFn.

  • Limit file size

    Check the size in PHP, and set maxSize in the picker.

  • Use random names

    Filestack stores each file under a unique handle.

  • Store outside the web root

    Filestack storage or your own bucket keeps uploads off the web server.

  • Scan for viruses and malware

    Virus detection runs in Workflows on any file type, on paid plans.

  • Sign every request

    Your endpoint returns a short-lived policy and its HMAC-SHA256 signature. The browser passes both to filestack.init(), and your app secret stays on the server.

  • Allow your domains

    Domain allow-lists accept uploads from the sites you list.

  • Keep an event log

    The developer portal logs uploads, edits, conversions and deletions.

policy.php
<?php
$policy = strtr(base64_encode(json_encode([
  'expiry' => time() + 3600,
  'call' => ['pick', 'store'],
])), '+/', '-_');
$signature = hash_hmac('sha256', $policy, getenv('FILESTACK_APP_SECRET'));

header('Content-Type: application/json');
echo json_encode(['policy' => $policy, 'signature' => $signature]);

PHP Upload Script vs Filestack

A PHP upload script is yours to scale, patch and secure. Filestack runs the upload service, storage and scanning, so the build becomes configuration.

PHP upload script Filestack
php.ini limits Every upload passes through upload_max_filesize and post_max_size Browser uploads go straight to storage
Max file size Set by your server and php.ini Set by your plan
Resumable uploads One request per file Multipart with resume, and Intelligent Ingestion on paid plans
Storage Your server's disk Filestack storage, or your own S3, GCS or Azure
Virus scanning Your own scanner Virus detection in Workflows, on paid plans
Image processing GD or Imagick code you write URL transformations, or resize()->save()
Cloud sources Local files Google Drive, Dropbox, OneDrive, Box, URL, camera and more
Maintenance Your team patches and scales the script Filestack runs the upload service

A native script suits small internal tools.

Laravel, WordPress and Plain PHP

The Filestack PHP SDK works in Laravel, Symfony and plain PHP, and WordPress sites use the Filestack plugin.

  • Laravel file upload

    Validate the request, then pass the uploaded file's real path to upload() with its original name.

  • WordPress

    The Filestack WordPress plugin adds the picker and CDN delivery to your site.

  • Plain PHP and Symfony

    Require Composer's autoloader and call $client->upload() from any controller or script.

UploadController.php
use Filestack\FilestackClient;
use Illuminate\Http\Request;

public function store(Request $request)
{
  $request->validate(['file' => 'required|file|max:10240']);
  $file = $request->file('file');
  $client = new FilestackClient(config('services.filestack.key'));
  $filelink = $client->upload($file->getRealPath(), [
    'filename' => $file->getClientOriginalName(),
  ]);
  return ['handle' => $filelink->handle, 'url' => $filelink->url()];
}

Store PHP Uploads in Your Own S3 Bucket

To upload PHP files to your own S3 bucket, connect the bucket in the developer portal, then pass ['location' => 's3'] to upload(). Files land in your bucket, and PHP keeps the handle. Storage docs

s3.php
<?php
// From PHP
$filelink = $client->upload('/path/to/file.pdf', ['location' => 's3']);

// From the browser: picker option storeTo: { location: 's3' }

Secure PHP file upload in minutes.

  • Most teams ship their first upload in under a day
  • Trusted by 100,000+ applications
  • SOC 2 compliant

PHP File Upload FAQs

How do I upload a file in PHP?

Post a form with enctype="multipart/form-data", check $_FILES['field']['error'], size and MIME type, then call move_uploaded_file() to save it outside the web root. With Filestack, $client->upload() stores it in cloud storage.

What does PHP need to populate $_FILES?

A POST form with enctype="multipart/form-data", file_uploads turned on in php.ini, and a request smaller than post_max_size. A larger request arrives with $_FILES empty.

How do I increase the PHP upload size limit?

Raise upload_max_filesize and post_max_size in php.ini, your PHP-FPM pool or .htaccess, then restart PHP. With File Picker, files go straight to storage and upload size follows your Filestack plan.

How do I upload multiple files in PHP?

Name the input with brackets, such as photos[], and add multiple. PHP groups the files under $_FILES['photos'], and you loop over tmp_name with the same checks.

How do I make PHP file uploads secure?

Check the error code and size, read the MIME type with finfo, store files under random names outside the web root, and scan them. Filestack adds signed policies, domain allow-lists and virus detection on paid plans.

Does the Filestack PHP SDK work with Laravel?

Yes. Install filestack/filestack-php with Composer and call $client->upload() in a controller with the uploaded file’s real path.

Is there a free plan for PHP file uploads with Filestack?

Yes. Filestack has a free plan for getting started, and paid plans add virus detection, webhooks and Intelligent Ingestion. See pricing.