https://github.com/dimo414/imgupload
Utility to support user-uploaded images to a PHP server
https://github.com/dimo414/imgupload
image-processing php
Last synced: over 1 year ago
JSON representation
Utility to support user-uploaded images to a PHP server
- Host: GitHub
- URL: https://github.com/dimo414/imgupload
- Owner: dimo414
- License: gpl-3.0
- Created: 2020-01-17T07:09:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-17T07:10:05.000Z (over 6 years ago)
- Last Synced: 2025-01-17T20:46:25.947Z (over 1 year ago)
- Topics: image-processing, php
- Language: PHP
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Secure Image Uploader
Easy, secure image uploader for handling form submissions with PHP
## Usage
The `ImgUploader` class is very self contained, all you really need to know for basic usage is as follows:
* Constructor
Pass to the constructor the information of one item in the `$_FILES` array - for instance
`$_FILES['uploadedImage']` if your form used the name `uploadedImage`.
* `upload_unscaled()`
`upload_unscaled()` takes two parameters, a directory (or series of directories) and a filename *without* the extension.
the directories should be from the web root (though you can of course use ../ to navigate above that).
the filename will be appended with the appropriate extension automatically.
* `upload()`
`upload()` takes two additional parameters to `upload_unscaled()`, a maximum width and height for the image.
The final image will be scaled down so it is no larger than either the width or height passed.
there is an optional fifth parameter which defaults to false which ensure that images smaller
than the maximum width and height are not scaled up.
Passing true to this parameter will scale up small images, though this may reduce quality.
`upload_unscaled()` and `upload()` can be called as many times as needed, for instance to create
a thumbnail in one directory, a medium image in another, and the full sized image
(using `upload_unscaled()`) in an third directory.
## Details
### Maximum File Size
This script will allow images up to 5MB. To change that, simply modify the if statement on line 55.
The script does not use the `MAX_FILE_SIZE` parameter of the HTML form since a malicious user can easily spoof that value.
### Error Checking
Both `upload_unscaled()` and `upload()` return false on failure, or the location of the image (from the web root) on success.
Any failure, be it at upload time, not an image, or a non-existent directory, will return false.
Call `getError()` to return the associated error code and handle the error accordingly.
Possible Errors and their codes:
* 101 - File is too large
* 102 - Upload failed or was interrupted
* 103 - File was not uploaded
* 104 - File is not an image
* 105 - File is not an acceptable image (gif, jpeg, png)
* 106 - File could not be saved because the directory does not exist
--------------------------------------------------------------------------------
## Example Usage
See `imguploader.test.php` for a more complete example:
upload('images/demoFile', '1000', 400,400))
echo '
';
// will output as
assuming file is a jpg
else
echo 'ERROR! '.$img->getError();
}
?>
## Copyright
Copyright 2007 Michael Diamond
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .