I use Bulletproof to handle image uploads in PHP and it is awesome. I am now working with a multipart form which will send images as well as other file types (specifically .pdf, .doc and .docx). I saw this question where the author of Bulletproof class mentioned that it would take 5 mins to modify the class to handle other file types. I have tried changing the mime types defined in the class as well as manually defining them in my code while invoking the class but I seem to be missing something. Has anyone had any luck with this before? I am posting this as a new question because I can't comment on other questions yet and have not found the answer to this on SO
Modifying PHP Bulletproof to handle non image uploads
216 views Asked by Mimzo At
1
There are 1 answers
Related Questions in PHP
- How to add the dynamic new rows from my registration form in my database?
- Issue in payment form gateway
- How to create a facet for WP gridbuilder that displays both parent and child custom fields?
- Function in anonymous Laravel Blade component
- How to change woocomerce or full wordpress currency with value from USD to AUD
- General questions about creating a custom theme Moodle CMS
- How to add logging to an abstract class in php
- error 500 on IIS FastCGI but no clue despite multiple error loggings activated
- Composer installation fails and reverts ./composer.json and ./composer.lock to original content
- How to isolate PHP apps from each other on a local machine(Windows or Linux)?
- Laravel: Using belongsToMany relationship with MongoDB
- window.location.href redirects but is causing problems on the webpage
- Key provided is shorter than 256 bits, only 64 bits provided
- Laravel's whereBetween method not working with two timestamps
- Implementing UUID as primary key in Laravel intermediate table
Related Questions in BULLETPROOF
- Bulletproof image uploader setName() function seems broken
- How to upload blob with Bulletproof php
- PHP - Upload Multiple Files with Bulletproof Library
- Modifying PHP Bulletproof to handle non image uploads
- Can bulletproof php upload pdf and word files?
- Uploading image to my php server from Android
- BulletProof's image class not uploading at all
- move_uploaded_file - prevent rotation / ignore exif data
- Resizing images before upload when using BulletProof upload class
- Writing test cases in unit-testing for file/image uploads
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
I know this is old, somehow didn't see it despite subscribing to the bulletproof tag.
So, to modify the class and enable it to upload a file type you want, then you have to modify a couple of lines.
First, there is a compiled list of acceptable MimeTypes that are stored in [
$imageMimes](https://github.com/samayo/bulletproof/blob/master/src/bulletproof.php#L72-L77)variable. In this file you have to add MimeType of the file you want to upload: ex: for PDF it would beapplication/pdfThen you have to remove lines that check the images width/height in pixels or MimeType that expects it to be an image from this, this, this and this line.
That will get rid of the function that checks image dimension or mime from being called. So, you can't use
$image->height,$image->widthor$image->mimeanywhere.To recap, this would be you should do it:
And when you have to upload, you should pass the mime types you want to set via the
setMime()function as:I'm working on a version that does not force you to manually edit the file to make similar changes. But for now, follow my example and understand the only constraints to upload anyfile with Bulletproof lies on the functions that check/get image height, width or MimeType.
If you remove the MimeType verifications from inside the
upload(){}method then know you have to add a code to check if the type you set is the same as the uploaded one.