-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
Concrete fixes for the problems people hit most often.
You called to() without first calling setFile().
$upload->setFile($file)->to(); // setFile() is required before to()If you are looping over File::setPost() and the loop never runs, the field
was empty or absent — setPost() returned []. Check the form's name
attribute and that it has enctype="multipart/form-data".
The file's extension is not in allowed_extensions. Remember:
- Matching is case-insensitive, so you only need
['jpg'], not['jpg','JPG']. - The extension comes from the original name. A file with no extension
(
README) has an empty extension and fails any non-empty allow-list.
The real MIME type (from finfo) is not in allowed_mime_types. This is
working as intended when a file's real content differs from its name. To see
what finfo detected:
echo $file->getRealMimeType();If a legitimate file is rejected, add its real type to the list (e.g. some
browsers send image/jpg while finfo reports image/jpeg).
The file is larger than allowed_max_size (which is in bytes). Raise the
limit, or compress the file. Also confirm your php.ini limits are high enough:
upload_max_filesize = 16M
post_max_size = 20MA file over the PHP limits arrives with an upload error code, surfacing as "The file upload failed with error code N." instead.
The browser/PHP reported an UPLOAD_ERR_*
problem before validation:
| N | Constant | Meaning |
|---|---|---|
| 1 | UPLOAD_ERR_INI_SIZE |
Bigger than upload_max_filesize. |
| 2 | UPLOAD_ERR_FORM_SIZE |
Bigger than the form's MAX_FILE_SIZE. |
| 3 | UPLOAD_ERR_PARTIAL |
Only part of the file was received. |
| 6 | UPLOAD_ERR_NO_TMP_DIR |
No temp directory configured. |
| 7 | UPLOAD_ERR_CANT_WRITE |
Could not write to disk. |
Fix the underlying server setting; codes 6 and 7 are server-side misconfiguration.
Not an exception — the write itself failed. Common causes:
-
Local:
diris not writable by the PHP process, or could not be created. Check ownership/permissions. -
FTP: the
ftp_fputtransfer returned false (server rejected the path or ran out of space). -
S3: the SDK response carried no
ObjectURL.
- Confirm
diris what you think — logrealpath($dir). - Remember
$targetis appended underdir.to('a/b')⇒<dir>/a/b/<name>. - The public URL is
url+/+ the same prefixed name; if the URL is wrong, fixurl, not the storage path.
There is no automatic collision protection. Generate unique names with
rename() — see Recipes.
-
Passive mode. Behind NAT/firewalls, active mode often stalls. Passive is
the default; make sure you did not set
'passive' => false. -
Credentials. "FTP username or password incorrect!" means login failed —
verify
username/password. -
Connection. "FTP connection failed." means the host/port was
unreachable — check
host,port, and network/firewall rules; raisetimeoutfor slow links. -
ext-ftpmissing. AnUnsupportedExceptionat construction means the FTP extension is not installed (php -m | grep ftp). -
Corrupted binaries? This package always transfers in
FTP_BINARY, so corruption from this library should not happen; if it does, suspect the server or an intermediate proxy.
ext-ftp is not loaded. Install/enable it, or use a different adapter.
The aws/aws-sdk-php package is missing:
composer require aws/aws-sdk-phpThe underlying AWS exception is wrapped — read the cause:
catch (\InitPHP\Upload\Exceptions\UploadException $e) {
$aws = $e->getPrevious(); // the original Aws\S3\Exception\S3Exception
error_log((string) $aws);
}Common causes: wrong region, a non-existent bucket, invalid
key/secret_key, or an IAM policy that forbids s3:PutObject.
This adapter configures the SDK with version, region and credentials only.
Providers that need a custom endpoint / path-style addressing (MinIO,
Cloudflare R2, DigitalOcean Spaces) are best driven by constructing
Aws\S3\S3Client yourself with the right options, then uploading through the
SDK. For most AWS-hosted buckets the adapter works as-is.
Open an issue with your PHP version, the adapter, the exact message, and a minimal reproducer. Doc and bug fixes are merged eagerly.
initphp/upload · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Reference
Adapters
Practical Guides
Other