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
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.