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

Image uploading on IIS(windows) results in tmp file in given directory #152

Closed raizdev closed 2 years ago

raizdev commented 2 years ago

Debian webserver works fine, when i switch to IIS the image stays at tmp file in upload directory.

verot commented 2 years ago

Please note that IIS is not officialy supported. But anyhow, can you paste here the log produced by the class?

raizdev commented 2 years ago

Cosmic\App\Library\Upload Object ( [version] => 03/08/2019 [file_src_name] => phpD2A1.tmp [file_src_name_body] => phpD2A1 [file_src_name_ext] => tmp [file_src_mime] => image/jpeg [file_src_size] => 407109 [file_src_error] => 0 [file_src_pathname] => C:\Windows\Temp\phpD2A1.tmp [file_src_temp] => [file_dst_path] => [file_dst_name] => [file_dst_name_body] => [file_dst_name_ext] => [file_dst_pathname] => [image_src_x] => 1600 [image_src_y] => 1200 [image_src_bits] => 8 [image_src_pixels] => 1920000 [image_src_type] => jpg [image_dst_x] => 1600 [image_dst_y] => 1200 [image_dst_type] => [image_supported] => Array ( [image/gif] => gif [image/jpg] => jpg [image/jpeg] => jpg [image/pjpeg] => jpg [image/png] => png [image/x-png] => png [image/webp] => webp [image/x-webp] => webp [image/bmp] => bmp [image/x-ms-bmp] => bmp [image/x-windows-bmp] => bmp ) [file_is_image] => 1 [uploaded] => 1 [no_upload_check] => 1 [processed] => [error] => [log] => system information

verot commented 2 years ago

This is not really the log. You should output $handle->log after calling process() Anyway, I think your problem is that you want to process a local file (in /tmp), and then wonder why the file remains in /tmp after being processed. It is normal behaviour, so that you can process a same file several times (for instance to produce several thumbnails). In order to delete the original file, you need to call clean() after calling process()

raizdev commented 2 years ago

system information
- class version: 03/08/2019
- operating system: WINNT
- PHP version: 8.0 .0
- GD version: 2.1 .0
- supported image types: png webp jpg gif bmp
- open_basedir: no restriction
- upload_max_filesize: 2 M(2097152 bytes)
- language: en_GB
source is a local file C: \Windows\Temp\php9FDC.tmp
-local file OK
determining MIME type
-Checking MIME type with Fileinfo PECL extension
    Fileinfo PECL extension not available
-Checking MIME type with UNIX file()command
    UNIX file()command not availabled
-Checking MIME type with mime.magic file(mime_content_type())
    mime_content_type()is not available
-Checking MIME type with getimagesize()
    MIME type detected as image/png by PHP getimagesize()function
- MIME validated as image/png
source variables
-You can use all these before calling process()
    file_src_name: php9FDC.tmp
    file_src_name_body: php9FDC
    file_src_name_ext: tmp
    file_src_pathname: C: \Windows\Temp\php9FDC.tmp
    file_src_mime: image/png
    file_src_size: 291412(max=2097152)
    file_src_error: 0
-source file is an image
    image_src_x: 1000
    image_src_y: 343
    image_src_pixels: 343000
    image_src_type: png
    image_src_bits: 8
process file to C: \inetpub\wwwroot\Cosmic\src\App\Controllers\Admin/../../../../public/uploads/\
-file size OK
-file mime OK: image/png
-new file name body: 61701 ee1a3197
-file name safe format
-destination variables
    file_dst_path: C: \inetpub\wwwroot\Cosmic\src\App\Controllers\Admin/../../../../public/uploads/\
    file_dst_name_body: 61701 ee1a3197
    file_dst_name_ext: tmp
-checking for auto_rename
-destination file details
    file_dst_name: 61701 ee1a3197.tmp
    file_dst_pathname: C: \inetpub\wwwroot\Cosmic\src\App\Controllers\Admin/../../../../public/uploads/\61701 ee1a3197.tmp
-61701 ee1a3197.tmp doesn 't exist already
- auto-rotate requires function exif_read_data to be enabled
- no image processing wanted
- process OK
{"status":"success","message":"News edit successfully"}

raizdev commented 2 years ago

It looks like that he can write the tmp file to the given path C: \inetpub\wwwroot\Cosmic\src\App\Controllers\Admin/../../../../public/uploads/\

But when it try to rename it he can't find the file

verot commented 2 years ago

You provide an incorrct path to the class when calling process() : C:\inetpub\wwwroot\Cosmic\src\App\Controllers\Admin/../../../../public/uploads/

raizdev commented 2 years ago

Should be fine, where does \ come from? $this->file->process(__DIR__ . '/../../../../public/uploads/');

verot commented 2 years ago

I am not sure, I don't use Windows. But other users have reported that the class works fine on Windows and IIS.

raizdev commented 2 years ago

Weird. over 500 people using my CMS and all of them reports that it doesnt work. Thanks

verot commented 2 years ago

I mean the class does work on Windows (IIS, XAMP...). But your implementation is not correct. __DIR__ . '/../../../../public/uploads/' results in C: \inetpub\wwwroot\Cosmic\src\App\Controllers\Admin/../../../../public/uploads/ The end \ is automatically added, and it is a backslash since you run on Windows: https://github.com/verot/class.upload.php/blob/4f6c0aad06a4777d3eddc480fd3e25a2cdc0a8ff/src/class.upload.php#L3089-L3093

raizdev commented 2 years ago

Allright, i will take a look on it, thanks :)