verot/class.upload.php

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

raizdev opened this issue · 11 comments

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

verot commented

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

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

  • 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 : 2M (2097152 bytes)
  • language : en_GB
    source is a local file C:\Windows\Temp\phpD2A1.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/jpeg by PHP getimagesize() function
  • MIME validated as image/jpeg
    source variables
  • You can use all these before calling process()
    file_src_name : phpD2A1.tmp
    file_src_name_body : phpD2A1
    file_src_name_ext : tmp
    file_src_pathname : C:\Windows\Temp\phpD2A1.tmp
    file_src_mime : image/jpeg
    file_src_size : 407109 (max= 2097152)
    file_src_error : 0
  • source file is an image
    image_src_x : 1600
    image_src_y : 1200
    image_src_pixels : 1920000
    image_src_type : jpg
    image_src_bits : 8
    [file_new_name_body] => [file_name_body_add] => [file_name_body_pre] => [file_new_name_ext] => [file_safe_name] => 1 [file_force_extension] => 1 [mime_check] => 1 [mime_fileinfo] => 1 [mime_file] => 1 [mime_magic] => 1 [mime_getimagesize] => 1 [no_script] => 1 [file_auto_rename] => 1 [dir_auto_create] => 1 [dir_auto_chmod] => 1 [dir_chmod] => 493 [file_overwrite] => [file_max_size] => 2097152 [image_resize] => [image_convert] => [image_x] => 150 [image_y] => 150 [image_ratio] => [image_ratio_crop] => [image_ratio_fill] => [image_ratio_pixels] => [image_ratio_x] => [image_ratio_y] => [image_ratio_no_zoom_in] => [image_ratio_no_zoom_out] => [image_no_enlarging] => [image_no_shrinking] => [image_max_width] => [image_max_height] => [image_max_pixels] => [image_max_ratio] => [image_min_width] => [image_min_height] => [image_min_pixels] => [image_min_ratio] => [png_compression] => [jpeg_quality] => 85 [webp_quality] => 85 [jpeg_size] => [image_interlace] => [image_is_transparent] => [image_transparent_color] => [image_background_color] => [image_default_color] => #ffffff [image_is_palette] => [image_brightness] => [image_contrast] => [image_opacity] => [image_threshold] => [image_tint_color] => [image_overlay_color] => [image_overlay_opacity] => [image_negative] => [image_greyscale] => [image_pixelate] => [image_unsharp] => [image_unsharp_amount] => 80 [image_unsharp_radius] => 0.5 [image_unsharp_threshold] => 1 [image_text] => [image_text_direction] => [image_text_color] => #FFFFFF [image_text_opacity] => 100 [image_text_background] => [image_text_background_opacity] => 100 [image_text_font] => 5 [image_text_size] => 16 [image_text_angle] => [image_text_position] => [image_text_x] => [image_text_y] => [image_text_padding] => 0 [image_text_padding_x] => [image_text_padding_y] => [image_text_alignment] => C [image_text_line_spacing] => 0 [image_reflection_height] => [image_reflection_space] => 2 [image_reflection_opacity] => 60 [image_auto_rotate] => 1 [image_flip] => [image_rotate] => [image_crop] => [image_precrop] => [image_bevel] => [image_bevel_color1] => #FFFFFF [image_bevel_color2] => #000000 [image_border] => [image_border_color] => #FFFFFF [image_border_opacity] => 100 [image_border_transparent] => [image_frame] => [image_frame_colors] => #FFFFFF #999999 #666666 #000000 [image_frame_opacity] => 100 [image_watermark] => [image_watermark_position] => [image_watermark_x] => [image_watermark_y] => [image_watermark_no_zoom_in] => 1 [image_watermark_no_zoom_out] => [mime_types] => Array ( [jpg] => image/jpeg [jpeg] => image/jpeg [jpe] => image/jpeg [gif] => image/gif [webp] => image/webp [png] => image/png [bmp] => image/bmp [flif] => image/flif [flv] => video/x-flv [js] => application/x-javascript [json] => application/json [tiff] => image/tiff [css] => text/css [xml] => application/xml [doc] => application/msword [xls] => application/vnd.ms-excel [xlt] => application/vnd.ms-excel [xlm] => application/vnd.ms-excel [xld] => application/vnd.ms-excel [xla] => application/vnd.ms-excel [xlc] => application/vnd.ms-excel [xlw] => application/vnd.ms-excel [xll] => application/vnd.ms-excel [ppt] => application/vnd.ms-powerpoint [pps] => application/vnd.ms-powerpoint [rtf] => application/rtf [pdf] => application/pdf [html] => text/html [htm] => text/html [php] => text/html [txt] => text/plain [mpeg] => video/mpeg [mpg] => video/mpeg [mpe] => video/mpeg [mp3] => audio/mpeg3 [wav] => audio/wav [aiff] => audio/aiff [aif] => audio/aiff [avi] => video/msvideo [wmv] => video/x-ms-wmv [mov] => video/quicktime [zip] => application/zip [tar] => application/x-tar [swf] => application/x-shockwave-flash [odt] => application/vnd.oasis.opendocument.text [ott] => application/vnd.oasis.opendocument.text-template [oth] => application/vnd.oasis.opendocument.text-web [odm] => application/vnd.oasis.opendocument.text-master [odg] => application/vnd.oasis.opendocument.graphics [otg] => application/vnd.oasis.opendocument.graphics-template [odp] => application/vnd.oasis.opendocument.presentation [otp] => application/vnd.oasis.opendocument.presentation-template [ods] => application/vnd.oasis.opendocument.spreadsheet [ots] => application/vnd.oasis.opendocument.spreadsheet-template [odc] => application/vnd.oasis.opendocument.chart [odf] => application/vnd.oasis.opendocument.formula [odb] => application/vnd.oasis.opendocument.database [odi] => application/vnd.oasis.opendocument.image [oxt] => application/vnd.openofficeorg.extension [docx] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [docm] => application/vnd.ms-word.document.macroEnabled.12 [dotx] => application/vnd.openxmlformats-officedocument.wordprocessingml.template [dotm] => application/vnd.ms-word.template.macroEnabled.12 [xlsx] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [xlsm] => application/vnd.ms-excel.sheet.macroEnabled.12 [xltx] => application/vnd.openxmlformats-officedocument.spreadsheetml.template [xltm] => application/vnd.ms-excel.template.macroEnabled.12 [xlsb] => application/vnd.ms-excel.sheet.binary.macroEnabled.12 [xlam] => application/vnd.ms-excel.addin.macroEnabled.12 [pptx] => application/vnd.openxmlformats-officedocument.presentationml.presentation [pptm] => application/vnd.ms-powerpoint.presentation.macroEnabled.12 [ppsx] => application/vnd.openxmlformats-officedocument.presentationml.slideshow [ppsm] => application/vnd.ms-powerpoint.slideshow.macroEnabled.12 [potx] => application/vnd.openxmlformats-officedocument.presentationml.template [potm] => application/vnd.ms-powerpoint.template.macroEnabled.12 [ppam] => application/vnd.ms-powerpoint.addin.macroEnabled.12 [sldx] => application/vnd.openxmlformats-officedocument.presentationml.slide [sldm] => application/vnd.ms-powerpoint.slide.macroEnabled.12 [thmx] => application/vnd.ms-officetheme [onetoc] => application/onenote [onetoc2] => application/onenote [onetmp] => application/onenote [onepkg] => application/onenote [csv] => text/csv ) [allowed] => Array ( [0] => application/arj [1] => application/excel [2] => application/gnutar [3] => application/mspowerpoint [4] => application/msword [5] => application/octet-stream [6] => application/onenote [7] => application/pdf [8] => application/plain [9] => application/postscript [10] => application/powerpoint [11] => application/rar [12] => application/rtf [13] => application/vnd.ms-excel [14] => application/vnd.ms-excel.addin.macroEnabled.12 [15] => application/vnd.ms-excel.sheet.binary.macroEnabled.12 [16] => application/vnd.ms-excel.sheet.macroEnabled.12 [17] => application/vnd.ms-excel.template.macroEnabled.12 [18] => application/vnd.ms-office [19] => application/vnd.ms-officetheme [20] => application/vnd.ms-powerpoint [21] => application/vnd.ms-powerpoint.addin.macroEnabled.12 [22] => application/vnd.ms-powerpoint.presentation.macroEnabled.12 [23] => application/vnd.ms-powerpoint.slide.macroEnabled.12 [24] => application/vnd.ms-powerpoint.slideshow.macroEnabled.12 [25] => application/vnd.ms-powerpoint.template.macroEnabled.12 [26] => application/vnd.ms-word [27] => application/vnd.ms-word.document.macroEnabled.12 [28] => application/vnd.ms-word.template.macroEnabled.12 [29] => application/vnd.oasis.opendocument.chart [30] => application/vnd.oasis.opendocument.database [31] => application/vnd.oasis.opendocument.formula [32] => application/vnd.oasis.opendocument.graphics [33] => application/vnd.oasis.opendocument.graphics-template [34] => application/vnd.oasis.opendocument.image [35] => application/vnd.oasis.opendocument.presentation [36] => application/vnd.oasis.opendocument.presentation-template [37] => application/vnd.oasis.opendocument.spreadsheet [38] => application/vnd.oasis.opendocument.spreadsheet-template [39] => application/vnd.oasis.opendocument.text [40] => application/vnd.oasis.opendocument.text-master [41] => application/vnd.oasis.opendocument.text-template [42] => application/vnd.oasis.opendocument.text-web [43] => application/vnd.openofficeorg.extension [44] => application/vnd.openxmlformats-officedocument.presentationml.presentation [45] => application/vnd.openxmlformats-officedocument.presentationml.slide [46] => application/vnd.openxmlformats-officedocument.presentationml.slideshow [47] => application/vnd.openxmlformats-officedocument.presentationml.template [48] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [49] => application/vnd.openxmlformats-officedocument.spreadsheetml.template [50] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [51] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [52] => application/vnd.openxmlformats-officedocument.wordprocessingml.template [53] => application/vocaltec-media-file [54] => application/wordperfect [55] => application/haansoftxlsx [56] => application/x-bittorrent [57] => application/x-bzip [58] => application/x-bzip2 [59] => application/x-compressed [60] => application/x-excel [61] => application/x-gzip [62] => application/x-latex [63] => application/x-midi [64] => application/xml [65] => application/x-msexcel [66] => application/x-rar [67] => application/x-rar-compressed [68] => application/x-rtf [69] => application/x-shockwave-flash [70] => application/x-sit [71] => application/x-stuffit [72] => application/x-troff-msvideo [73] => application/x-zip [74] => application/x-zip-compressed [75] => application/zip [76] => audio/* [77] => image/* [78] => multipart/x-gzip [79] => multipart/x-zip [80] => text/plain [81] => text/rtf [82] => text/richtext [83] => text/xml [84] => video/* [85] => text/csv [86] => text/x-c [87] => text/x-csv [88] => text/comma-separated-values [89] => text/x-comma-separated-values [90] => application/csv [91] => application/x-csv ) [forbidden] => Array ( ) [blacklist] => Array ( [0] => php [1] => php7 [2] => php6 [3] => php5 [4] => php4 [5] => php3 [6] => phtml [7] => pht [8] => phpt [9] => phtm [10] => phps [11] => inc [12] => pl [13] => py [14] => cgi [15] => asp [16] => js [17] => sh [18] => phar ) [translation] => Array ( [file_error] => File error. Please try again. [local_file_missing] => Local file doesn't exist. [local_file_not_readable] => Local file is not readable. [uploaded_too_big_ini] => File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini). [uploaded_too_big_html] => File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form). [uploaded_partial] => File upload error (the uploaded file was only partially uploaded). [uploaded_missing] => File upload error (no file was uploaded). [uploaded_no_tmp_dir] => File upload error (missing a temporary folder). [uploaded_cant_write] => File upload error (failed to write file to disk). [uploaded_err_extension] => File upload error (file upload stopped by extension). [uploaded_unknown] => File upload error (unknown error code). [try_again] => File upload error. Please try again. [file_too_big] => File too big. [no_mime] => MIME type can't be detected. [incorrect_file] => Incorrect type of file. [image_too_wide] => Image too wide. [image_too_narrow] => Image too narrow. [image_too_high] => Image too tall. [image_too_short] => Image too short. [ratio_too_high] => Image ratio too high (image too wide). [ratio_too_low] => Image ratio too low (image too high). [too_many_pixels] => Image has too many pixels. [not_enough_pixels] => Image has not enough pixels. [file_not_uploaded] => File not uploaded. Can't carry on a process. [already_exists] => %s already exists. Please change the file name. [temp_file_missing] => No correct temp source file. Can't carry on a process. [source_missing] => No correct uploaded source file. Can't carry on a process. [destination_dir] => Destination directory can't be created. Can't carry on a process. [destination_dir_missing] => Destination directory doesn't exist. Can't carry on a process. [destination_path_not_dir] => Destination path is not a directory. Can't carry on a process. [destination_dir_write] => Destination directory can't be made writeable. Can't carry on a process. [destination_path_write] => Destination path is not a writeable. Can't carry on a process. [temp_file] => Can't create the temporary file. Can't carry on a process. [source_not_readable] => Source file is not readable. Can't carry on a process. [no_create_support] => No create from %s support. [create_error] => Error in creating %s image from source. [source_invalid] => Can't read image source. Not an image?. [gd_missing] => GD doesn't seem to be present. [watermark_no_create_support] => No create from %s support, can't read watermark. [watermark_create_error] => No %s read support, can't create watermark. [watermark_invalid] => Unknown image format, can't read watermark. [file_create] => No %s create support. [no_conversion_type] => No conversion type defined. [copy_failed] => Error copying file on the server. copy() failed. [reading_failed] => Error reading the file. ) [lang] => en_GB [file_max_size_raw] => 2M )
verot commented

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()

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/</b>
-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/<br/>    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"}

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

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

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

verot commented

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

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

verot commented

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:

if(strtolower(substr(PHP_OS, 0, 3)) === 'win') {
if (substr($server_path, -1, 1) != '\\') $server_path = $server_path . '\\';
} else {
if (substr($server_path, -1, 1) != '/') $server_path = $server_path . '/';
}

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