{"id":28516259,"url":"https://github.com/delight-im/php-fileupload","last_synced_at":"2025-09-09T14:31:15.589Z","repository":{"id":49416813,"uuid":"84675310","full_name":"delight-im/PHP-FileUpload","owner":"delight-im","description":"Simple and convenient file uploads — secure by default","archived":false,"fork":false,"pushed_at":"2023-01-12T13:15:23.000Z","size":29,"stargazers_count":66,"open_issues_count":3,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-12T23:20:42.465Z","etag":null,"topics":["file","files","filesystem","form","input","php","upload","validation"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/delight-im.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-11T19:40:42.000Z","updated_at":"2025-05-20T14:50:33.000Z","dependencies_parsed_at":"2023-02-09T11:55:10.969Z","dependency_job_id":null,"html_url":"https://github.com/delight-im/PHP-FileUpload","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/delight-im/PHP-FileUpload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delight-im%2FPHP-FileUpload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delight-im%2FPHP-FileUpload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delight-im%2FPHP-FileUpload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delight-im%2FPHP-FileUpload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delight-im","download_url":"https://codeload.github.com/delight-im/PHP-FileUpload/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delight-im%2FPHP-FileUpload/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274311700,"owners_count":25262005,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file","files","filesystem","form","input","php","upload","validation"],"created_at":"2025-06-09T03:33:03.387Z","updated_at":"2025-09-09T14:31:15.574Z","avatar_url":"https://github.com/delight-im.png","language":"PHP","readme":"# PHP-FileUpload\n\nSimple and convenient file uploads — secure by default\n\n## Requirements\n\n * PHP 5.6.0+\n\n## Installation\n\n 1. Include the library via Composer [[?]](https://github.com/delight-im/Knowledge/blob/master/Composer%20(PHP).md):\n\n    ```\n    $ composer require delight-im/file-upload\n    ```\n\n 1. Include the Composer autoloader:\n\n    ```php\n    require __DIR__ . '/vendor/autoload.php';\n    ```\n\n 1. Set up your HTML form for the file upload, e.g.:\n\n    ```html\n    \u003cform action=\"\" method=\"post\" enctype=\"multipart/form-data\"\u003e\n        \u003cinput type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1048576\"\u003e\n        \u003cinput type=\"file\" name=\"my-input-name\"\u003e\n        \u003cbutton type=\"submit\"\u003eUpload\u003c/button\u003e\n    \u003c/form\u003e\n    ```\n\n    The two attributes `method=\"post\"` and `enctype=\"multipart/form-data\"` on the `\u003cform\u003e` element are mandatory. Likewise, there must be at least one `\u003cinput type=\"file\"\u003e` element with a proper `name` attribute. Finally, some way to submit the form, e.g. the `\u003cbutton type=\"submit\"\u003e` element, is required. The hidden input named `MAX_FILE_SIZE` is an optional hint for the client.\n\n## Usage\n\n * [File uploads](#file-uploads)\n   * [Limiting the maximum permitted file size](#limiting-the-maximum-permitted-file-size)\n   * [Reading the maximum permitted file size](#reading-the-maximum-permitted-file-size)\n   * [Restricting the allowed file types or extensions](#restricting-the-allowed-file-types-or-extensions)\n   * [Reading the allowed file types or extensions](#reading-the-allowed-file-types-or-extensions)\n   * [Reading the target directory](#reading-the-target-directory)\n   * [Defining the target filename](#defining-the-target-filename)\n   * [Reading the target filename](#reading-the-target-filename)\n   * [Reading the name of the input field](#reading-the-name-of-the-input-field)\n * [Base64 uploads](#base64-uploads)\n   * [Limiting the maximum permitted file size](#limiting-the-maximum-permitted-file-size-1)\n   * [Reading the maximum permitted file size](#reading-the-maximum-permitted-file-size-1)\n   * [Defining the filename extension](#defining-the-filename-extension)\n   * [Reading the filename extension](#reading-the-filename-extension)\n   * [Reading the target directory](#reading-the-target-directory-1)\n   * [Defining the target filename](#defining-the-target-filename-1)\n   * [Reading the target filename](#reading-the-target-filename-1)\n   * [Reading the Base64 data](#reading-the-base64-data)\n * [Data URI uploads](#data-uri-uploads)\n   * [Limiting the maximum permitted file size](#limiting-the-maximum-permitted-file-size-2)\n   * [Reading the maximum permitted file size](#reading-the-maximum-permitted-file-size-2)\n   * [Restricting the allowed MIME types and extensions](#restricting-the-allowed-mime-types-and-extensions)\n   * [Reading the allowed MIME types and extensions](#reading-the-allowed-mime-types-and-extensions)\n   * [Reading the target directory](#reading-the-target-directory-2)\n   * [Defining the target filename](#defining-the-target-filename-2)\n   * [Reading the target filename](#reading-the-target-filename-2)\n   * [Reading the data URI](#reading-the-data-uri)\n\n### File uploads\n\n```php\n$upload = new \\Delight\\FileUpload\\FileUpload();\n$upload-\u003ewithTargetDirectory('/my-app/users/' . $userId . '/avatars');\n$upload-\u003efrom('my-input-name');\n\ntry {\n    $uploadedFile = $upload-\u003esave();\n\n    // success\n\n    // $uploadedFile-\u003egetFilenameWithExtension()\n    // $uploadedFile-\u003egetFilename()\n    // $uploadedFile-\u003egetExtension()\n    // $uploadedFile-\u003egetDirectory()\n    // $uploadedFile-\u003egetPath()\n    // $uploadedFile-\u003egetCanonicalPath()\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InputNotFoundException $e) {\n    // input not found\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InvalidFilenameException $e) {\n    // invalid filename\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InvalidExtensionException $e) {\n    // invalid extension\n}\ncatch (\\Delight\\FileUpload\\Throwable\\FileTooLargeException $e) {\n    // file too large\n}\ncatch (\\Delight\\FileUpload\\Throwable\\UploadCancelledException $e) {\n    // upload cancelled\n}\n```\n\n#### Limiting the maximum permitted file size\n\n```php\n$upload-\u003ewithMaximumSizeInBytes(4194304);\n\n// or\n\n$upload-\u003ewithMaximumSizeInKilobytes(4096);\n\n// or\n\n$upload-\u003ewithMaximumSizeInMegabytes(4);\n```\n\n#### Reading the maximum permitted file size\n\n```php\n// e.g. int(4194304)\n$upload-\u003egetMaximumSizeInBytes();\n\n// or\n\n// e.g. int(4096)\n$upload-\u003egetMaximumSizeInKilobytes();\n\n// or\n\n// e.g. int(4)\n$upload-\u003egetMaximumSizeInMegabytes();\n```\n\n#### Restricting the allowed file types or extensions\n\n```php\n$upload-\u003ewithAllowedExtensions([ 'jpeg', 'jpg', 'png', 'gif' ]);\n```\n\n**Note:** By default, a set of filename extensions is used that is relatively safe for PHP applications and common on the web. This may be sufficient for some use cases.\n\n#### Reading the allowed file types or extensions\n\n```php\n// e.g. array(4) { [0]=\u003e string(4) \"jpeg\" [1]=\u003e string(3) \"jpg\" [2]=\u003e string(3) \"png\" [3]=\u003e string(3) \"gif\" }\n$upload-\u003egetAllowedExtensionsAsArray();\n\n// or\n\n// e.g. string(16) \"jpeg,jpg,png,gif\"\n$upload-\u003egetAllowedExtensionsAsMachineString();\n\n// or\n\n// e.g. string(19) \"JPEG, JPG, PNG, GIF\"\n$upload-\u003egetAllowedExtensionsAsHumanString();\n\n// or\n\n// e.g. string(21) \"JPEG, JPG, PNG or GIF\"\n$upload-\u003egetAllowedExtensionsAsHumanString(' or ');\n```\n\n#### Reading the target directory\n\n```php\n// e.g. string(24) \"/my-app/users/42/avatars\"\n$upload-\u003egetTargetDirectory();\n```\n\n#### Defining the target filename\n\n```php\n$upload-\u003ewithTargetFilename('my-picture');\n```\n\n**Note:** By default, a random filename will be used, which is sufficient (and desired) in many cases.\n\n#### Reading the target filename\n\n```php\n// e.g. string(10) \"my-picture\"\n$upload-\u003egetTargetFilename();\n```\n\n#### Reading the name of the input field\n\n```php\n// e.g. string(13) \"my-input-name\"\n$upload-\u003egetSourceInputName();\n```\n\n### Base64 uploads\n\n```php\n$upload = new \\Delight\\FileUpload\\Base64Upload();\n$upload-\u003ewithTargetDirectory('/my-app/users/' . $userId . '/avatars');\n$upload-\u003ewithData($_POST['my-base64']);\n\ntry {\n    $uploadedFile = $upload-\u003esave();\n\n    // success\n\n    // $uploadedFile-\u003egetFilenameWithExtension()\n    // $uploadedFile-\u003egetFilename()\n    // $uploadedFile-\u003egetExtension()\n    // $uploadedFile-\u003egetDirectory()\n    // $uploadedFile-\u003egetPath()\n    // $uploadedFile-\u003egetCanonicalPath()\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InputNotFoundException $e) {\n    // input not found\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InvalidFilenameException $e) {\n    // invalid filename\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InvalidExtensionException $e) {\n    // invalid extension\n}\ncatch (\\Delight\\FileUpload\\Throwable\\FileTooLargeException $e) {\n    // file too large\n}\ncatch (\\Delight\\FileUpload\\Throwable\\UploadCancelledException $e) {\n    // upload cancelled\n}\n```\n\n#### Limiting the maximum permitted file size\n\n```php\n$upload-\u003ewithMaximumSizeInBytes(4194304);\n\n// or\n\n$upload-\u003ewithMaximumSizeInKilobytes(4096);\n\n// or\n\n$upload-\u003ewithMaximumSizeInMegabytes(4);\n```\n\n#### Reading the maximum permitted file size\n\n```php\n// e.g. int(4194304)\n$upload-\u003egetMaximumSizeInBytes();\n\n// or\n\n// e.g. int(4096)\n$upload-\u003egetMaximumSizeInKilobytes();\n\n// or\n\n// e.g. int(4)\n$upload-\u003egetMaximumSizeInMegabytes();\n```\n\n#### Defining the filename extension\n\n```php\n$upload-\u003ewithFilenameExtension('png');\n```\n\n**Note:** This defines the filename extension of the file *to be uploaded*, which is a property of the `FileUpload` instance. It does *not* change the extension of any file *already* uploaded, which would be represented in a `File` instance. By default, the filename extension `bin` for arbitrary (binary) data will be used, which may be sufficient in some cases.\n\n#### Reading the filename extension\n\n```php\n// e.g. string(3) \"png\"\n$upload-\u003egetFilenameExtension();\n```\n\n**Note:** This retrieves the filename extension of the file *to be uploaded*, which is a property of the `FileUpload` instance. It does *not* read the extension of any file *already* uploaded, which would be represented in a `File` instance.\n\n#### Reading the target directory\n\n```php\n// e.g. string(24) \"/my-app/users/42/avatars\"\n$upload-\u003egetTargetDirectory();\n```\n\n#### Defining the target filename\n\n```php\n$upload-\u003ewithTargetFilename('my-picture');\n```\n\n**Note:** By default, a random filename will be used, which is sufficient (and desired) in many cases.\n\n#### Reading the target filename\n\n```php\n// e.g. string(10) \"my-picture\"\n$upload-\u003egetTargetFilename();\n```\n\n#### Reading the Base64 data\n\n```php\n// e.g. string(20) \"SGVsbG8sIFdvcmxkIQ==\"\n$upload-\u003egetData();\n```\n\n### Data URI uploads\n\n```php\n$upload = new \\Delight\\FileUpload\\DataUriUpload();\n$upload-\u003ewithTargetDirectory('/my-app/users/' . $userId . '/avatars');\n$upload-\u003ewithUri($_POST['my-data-uri']);\n\ntry {\n    $uploadedFile = $upload-\u003esave();\n\n    // success\n\n    // $uploadedFile-\u003egetFilenameWithExtension()\n    // $uploadedFile-\u003egetFilename()\n    // $uploadedFile-\u003egetExtension()\n    // $uploadedFile-\u003egetDirectory()\n    // $uploadedFile-\u003egetPath()\n    // $uploadedFile-\u003egetCanonicalPath()\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InputNotFoundException $e) {\n    // input not found\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InvalidFilenameException $e) {\n    // invalid filename\n}\ncatch (\\Delight\\FileUpload\\Throwable\\InvalidExtensionException $e) {\n    // invalid extension\n}\ncatch (\\Delight\\FileUpload\\Throwable\\FileTooLargeException $e) {\n    // file too large\n}\ncatch (\\Delight\\FileUpload\\Throwable\\UploadCancelledException $e) {\n    // upload cancelled\n}\n```\n\n#### Limiting the maximum permitted file size\n\n```php\n$upload-\u003ewithMaximumSizeInBytes(4194304);\n\n// or\n\n$upload-\u003ewithMaximumSizeInKilobytes(4096);\n\n// or\n\n$upload-\u003ewithMaximumSizeInMegabytes(4);\n```\n\n#### Reading the maximum permitted file size\n\n```php\n// e.g. int(4194304)\n$upload-\u003egetMaximumSizeInBytes();\n\n// or\n\n// e.g. int(4096)\n$upload-\u003egetMaximumSizeInKilobytes();\n\n// or\n\n// e.g. int(4)\n$upload-\u003egetMaximumSizeInMegabytes();\n```\n\n#### Restricting the allowed MIME types and extensions\n\n```php\n$upload-\u003ewithAllowedMimeTypesAndExtensions([\n    'image/jpeg' =\u003e 'jpg',\n    'image/png' =\u003e 'png',\n    'image/gif' =\u003e 'gif'\n]);\n```\n\n**Note:** By default, a set of MIME types is used that is relatively safe for PHP applications and common on the web. This may be sufficient for some use cases.\n\n#### Reading the allowed MIME types and extensions\n\n```php\n// e.g. array(3) { [0]=\u003e string(10) \"image/jpeg\" [1]=\u003e string(9) \"image/png\" [2]=\u003e string(9) \"image/gif\" }\n$upload-\u003egetAllowedMimeTypesAsArray();\n\n// or\n\n// e.g. string(30) \"image/jpeg,image/png,image/gif\"\n$upload-\u003egetAllowedMimeTypesAsMachineString();\n\n// or\n\n// e.g. string(32) \"image/jpeg, image/png, image/gif\"\n$upload-\u003egetAllowedMimeTypesAsHumanString();\n\n// or\n\n// e.g. string(34) \"image/jpeg, image/png or image/gif\"\n$upload-\u003egetAllowedMimeTypesAsHumanString(' or ');\n\n// or\n\n// e.g. array(3) { [0]=\u003e string(3) \"jpg\" [1]=\u003e string(3) \"png\" [2]=\u003e string(3) \"gif\" }\n$upload-\u003egetAllowedExtensionsAsArray();\n\n// or\n\n// e.g. string(11) \"jpg,png,gif\"\n$upload-\u003egetAllowedExtensionsAsMachineString();\n\n// or\n\n// e.g. string(13) \"JPG, PNG, GIF\"\n$upload-\u003egetAllowedExtensionsAsHumanString();\n\n// or\n\n// e.g. string(15) \"JPG, PNG or GIF\"\n$upload-\u003egetAllowedExtensionsAsHumanString(' or ');\n```\n\n#### Reading the target directory\n\n```php\n// e.g. string(24) \"/my-app/users/42/avatars\"\n$upload-\u003egetTargetDirectory();\n```\n\n#### Defining the target filename\n\n```php\n$upload-\u003ewithTargetFilename('my-picture');\n```\n\n**Note:** By default, a random filename will be used, which is sufficient (and desired) in many cases.\n\n#### Reading the target filename\n\n```php\n// e.g. string(10) \"my-picture\"\n$upload-\u003egetTargetFilename();\n```\n\n#### Reading the data URI\n\n```php\n// e.g. string(43) \"data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==\"\n$upload-\u003egetUri();\n```\n\n## Contributing\n\nAll contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.\n\n## License\n\nThis project is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelight-im%2Fphp-fileupload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelight-im%2Fphp-fileupload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelight-im%2Fphp-fileupload/lists"}