verot / class.upload.php

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP 4, 5, 7 and 8. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.
http://www.verot.net/php_class_upload.htm
GNU General Public License v2.0
847 stars 358 forks source link

mime_content_type(): Can only process string or stream arguments #124

Closed datomegasherly closed 4 years ago

datomegasherly commented 4 years ago

sometimes , specially in laravel : $this->file_src_pathname , in line 2484 class.upload.php , is not string and to use mime_content_type function , we should change that to string , because of that I change line 2484 to :

$this->file_src_mime = mime_content_type(strval($this->file_src_pathname));

and it's done

verot commented 4 years ago

In Laravel, you mean that file_src_pathname is not a string, so basically that the $file array has something else than a string for the key name or _tmpname? If it is not a string, what is it then?

datomegasherly commented 4 years ago

In Laravel, you mean that file_src_pathname is not a string, so basically that the $file array has something else than a string for the key name or _tmpname? If it is not a string, what is it then?

It's an Illuminate\Http\UploadedFile Object

verot commented 4 years ago

Could you provide a _vardump of the object $file as created by Laravel, which you are using to instantiate the class?

datomegasherly commented 4 years ago

Could you provide a _vardump of the object $file as created by Laravel, which you are using to instantiate the class?

sure ,

object(Illuminate\Http\UploadedFile)#265 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(12) "13093958.jpg" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(10) "image/jpeg" ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["hashName":protected]=> NULL ["pathName":"SplFileInfo":private]=> string(45) "C:\Users\Magic\AppData\Local\Temp\php6A0E.tmp" ["fileName":"SplFileInfo":private]=> string(11) "php6A0E.tmp" }

verot commented 4 years ago

I see. So I suppose I should cast the variables from $file into strings and integers before the class uses the array.

datomegasherly commented 4 years ago

I see. So I suppose I should cast the variables from $file into strings and integers before the class uses the array.

as you wish , I just find fastest way to resolve the problem , it's maybe not the best way . as my suggested way , "strval" function will get first "SplFileInfo" from object and return current string from _file_srcpathname

verot commented 4 years ago

Would you mind checking the code in master? I have added a fix in commit fd5b0e6

datomegasherly commented 4 years ago

I check that . when $file come from Laravel , in line 2210 , check that $file is array and omg! it's not an array and it's an object , and then it's not empty . after that , goes to line 2215 , and than , it has no substr (php: data: base64: ) . then it goes to line 2285 and pass the line 2299 . it's where to change ( LINE 2299 ) :

$this->file_src_pathname = (string)$file;

I check that . it's ok and uploaded successfully . at the end , thanks for your useful class

verot commented 4 years ago

I have pushed a new version to master. Does it work for you?

datomegasherly commented 4 years ago

that's working good , thanks