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
853 stars 359 forks source link

"Failed to load magic database" #158

Closed Shou-nen closed 2 years ago

Shou-nen commented 2 years ago

On my xampp local server when uploading an image:

E_WARNING | line 2452 | finfo_open(U:\extras\magic): Failed to open stream: No such file or directory E_WARNING | line 2452 | finfo_open(U:\extras\magic): Failed to open stream: No such file or directory E_WARNING | line 2452 | finfo_open(): Failed to load magic database at "U:\extras\magic"

The specified folder not exist and I can't see at all any folder named "magic' in my xampp, so the function probably shouldn't try to open it.

verot commented 2 years ago

The class should work on Windows, but it not supported. However, I will gladly accept a patch fixing this issue.

Shou-nen commented 2 years ago

Hmm, maybe just add checking if the folder exists in line 2451?

if ($path) { -> if ($path && file_exists($path)) {

emondpph commented 2 years ago

Yeah, I just stumbled on the same problem running my test suite on Windows... It seems you are trying to load a magic file which is internal in PHP 8.1 Windows and not required. The file_exists($path) should fix it.

Incredible class you did by the way, still useful a decade after.

verot commented 2 years ago

Hopefully fixed in 5a22579. Does it work with 8.1 on Windows? Would you be kind enough as to provide a log of an upload?

emondpph commented 2 years ago

system information

emondpph commented 2 years ago

It did fix my issue... I cannot say if the whole class is working as I am only using the resizing and compressing options. Thank you.

verot commented 2 years ago

It should be fine. The important line is "MIME type detected as image/jpeg; charset=binary by Fileinfo PECL extension" which indicates that on PHP 8.1, even though it cannot find the magic file, it manages to use the built-in one. Thank you!