{"id":17222681,"url":"https://github.com/samayo/bulletproof","last_synced_at":"2025-05-15T21:08:11.260Z","repository":{"id":10247122,"uuid":"12353328","full_name":"samayo/bulletproof","owner":"samayo","description":"Simple and secure image uploader in PHP","archived":false,"fork":false,"pushed_at":"2024-05-05T18:35:00.000Z","size":956,"stargazers_count":399,"open_issues_count":0,"forks_count":89,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-04-08T04:15:16.543Z","etag":null,"topics":["image","image-upload","image-uploader","php","php-image","security","upload"],"latest_commit_sha":null,"homepage":"","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/samayo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-08-25T02:59:35.000Z","updated_at":"2025-03-13T03:58:15.000Z","dependencies_parsed_at":"2024-05-05T19:22:46.518Z","dependency_job_id":"dd30da7d-6c2f-478e-84d6-e3b9ee5c4137","html_url":"https://github.com/samayo/bulletproof","commit_stats":{"total_commits":232,"total_committers":17,"mean_commits":"13.647058823529411","dds":"0.39224137931034486","last_synced_commit":"f25f732deed46ab1ba738ddf0ac676f20a802980"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayo%2Fbulletproof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayo%2Fbulletproof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayo%2Fbulletproof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samayo%2Fbulletproof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samayo","download_url":"https://codeload.github.com/samayo/bulletproof/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422789,"owners_count":22068679,"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","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":["image","image-upload","image-uploader","php","php-image","security","upload"],"created_at":"2024-10-15T04:06:06.360Z","updated_at":"2025-05-15T21:08:11.238Z","avatar_url":"https://github.com/samayo.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"## BULLETPROOF [![Test](https://github.com/samayo/bulletproof/actions/workflows/php.yml/badge.svg)](https://github.com/samayo/bulletproof/actions/workflows/php.yml)\r\n\r\n[![Latest Stable Version](https://poser.pugx.org/samayo/bulletproof/v/stable.svg?format=flat-square)](https://packagist.org/packages/samayo/bulletproof) [![Total Downloads](https://poser.pugx.org/samayo/bulletproof/downloads?format=flat-square)](https://packagist.org/packages/samayo/bulletproof?format=flat-square) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/samayo/bulletproof/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/samayo/bulletproof/?branch=master)  [![License](https://poser.pugx.org/samayo/bulletproof/license)](https://packagist.org/packages/fastpress/framework)\r\n\r\nBulletproof is a single-class PHP library to upload images securely.\r\n\r\nInstallation\r\n-----\r\n\r\nInstall using git\r\n```bash\r\n$ git clone https://github.com/samayo/bulletproof.git\r\n```\r\nInstall using Composer\r\n```bash\r\n$ composer require samayo/bulletproof:5.0.*\r\n```\r\nOr [download it manually][bulletproof_archive] in a ZIP format\r\n\r\nUsage\r\n-----\r\n\r\nTo quickly upload images, use the following HTML \u0026 PHP code:\r\n\r\n```html\r\n\u003cform method=\"POST\" enctype=\"multipart/form-data\"\u003e\r\n  \u003cinput type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\"/\u003e\r\n  \u003cinput type=\"file\" name=\"pictures\" accept=\"image/*\"/\u003e\r\n  \u003cinput type=\"submit\" value=\"upload\"/\u003e\r\n\u003c/form\u003e\r\n```\r\n```php \r\nrequire_once  \"path/to/bulletproof.php\";\r\n\r\n$image = new Bulletproof\\Image($_FILES);\r\n\r\nif($image[\"pictures\"]){\r\n  $upload = $image-\u003eupload(); \r\n\r\n  if($upload){\r\n    echo $upload-\u003egetPath(); // uploads/cat.gif\r\n  }else{\r\n    echo $image-\u003egetError(); \r\n  }\r\n}\r\n```\r\nFor more options or configurations, check the following examples:\r\n\r\n\r\nConfigs\r\n-----\r\n\r\n#### Setting Properties\r\nMethods to set restriction on the image name, size, type, etc.. to upload\r\n```php  \r\n// To provide a name for the image. If unused, image name will be auto-generated.\r\n$image-\u003esetName($name);\r\n\r\n// To set the min/max image size to upload (in bytes)\r\n$image-\u003esetSize($min, $max);\r\n\r\n// To define a list of allowed image types to upload\r\n$image-\u003esetMime(array('jpeg', 'gif'));\r\n\r\n// To set the max image height/width to upload (limit in pixels)\r\n$image-\u003esetDimension($width, $height);\r\n\r\n// To create a folder name to store the uploaded image, with optional chmod permission\r\n$image-\u003esetStorage($folderName, $optionalPermission);\r\n```\r\n\r\n#### Getting Properties\r\nMethods to retrieve image data before/after upload. \r\n```php \r\n// To get the image name\r\n$image-\u003egetName();\r\n\r\n// To get the image size (in bytes)\r\n$image-\u003egetSize();\r\n\r\n// To get the image mime (extension)\r\n$image-\u003egetMime();\r\n\r\n// To get the image width in pixels\r\n$image-\u003egetWidth();\r\n\r\n// To get the image height in pixels\r\n$image-\u003egetHeight();\r\n\r\n// To get image location (folder where images are uploaded)\r\n$image-\u003egetStorage();\r\n\r\n// To get the full image path. ex 'images/logo.jpg'\r\n$image-\u003egetPath();\r\n\r\n// To get the json format value of all the above information\r\n$image-\u003egetJson();\r\n```\r\n\r\n#### Extended Configuration Usage\r\nHow to use the property setters and getters. \r\n```php \r\n$image = new Bulletproof\\Image($_FILES);\r\n\r\n$image-\u003esetName(\"samayo\")\r\n      -\u003esetMime([\"gif\"])\r\n      -\u003esetStorage(__DIR__ . \"/avatars\");\r\n\r\nif($image[\"pictures\"]){\r\n  if($image-\u003eupload()){\r\n    echo $image-\u003egetName(); // samayo   \r\n    echo $image-\u003egetMime(); // gif\r\n    echo $image-\u003egetStorage(); // avatars\r\n    echo $image-\u003egetPath(); // avatars/samayo.gif\r\n  }\r\n}\r\n``` \r\n\r\n#### Image Manipulation\r\nTo crop, resize or watermak images, use functions stored in [`src/utils`][utils]\r\n\r\n#### Creating custom errors\r\nUse php exceptions to define custom error responses\r\n```php \r\nif($image['pictures']){\r\n  try {\r\n    if($image-\u003egetMime() !== 'png'){\r\n      throw new \\Exception('Only PNG image types are allowed');\r\n    }\r\n\r\n    // check size, width, height...\r\n\r\n    if(!$image-\u003eupload()){\r\n      throw new \\Exception($image-\u003egetError());\r\n    } else {\r\n      echo $image-\u003egetPath();\r\n    }\r\n    \r\n  } catch (\\Exception $e){\r\n    echo \"Error \" . $e-\u003egetMessage();\r\n  }\r\n}\r\n```\r\n\r\n#### What makes this secure?  \r\n* Uses **[`exif_imagetype()`][exif_imagetype_link]** to get the true image mime (`.extension`)\r\n* Uses **[`getimagesize()`][getimagesize_link]** to check if image has a valid height / width in pixels.\r\n* Sanitized images names, strict folder permissions and more... \r\n\r\n### License: MIT\r\n[utils]: https://github.com/samayo/bulletproof/tree/master/src/utils\r\n[bulletproof_archive]: https://github.com/samayo/bulletproof/releases\r\n[exif_imagetype_link]: https://php.net/manual/function.exif-imagetype.php\r\n[getimagesize_link]: https://php.net/manual/function.getimagesize.php\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamayo%2Fbulletproof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamayo%2Fbulletproof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamayo%2Fbulletproof/lists"}