SVG Images

See all posts Reply

SVG Images new!
by Dave Buchholz, 1 year ago
When I upload an svg image it is processed as a text file in that the resulting file name saved on the server is image-filename.svg.txt

Is this expected behaviour ? If so how can I upload svg images to the server and retain the .svg suffix ?

Thanks.Reply
Re: SVG Images new!
by colin, 1 year ago
Can you copy here the logs produced by the class? What is the MIME type of the SVG file as detected by the class?Reply
Re: SVG Images new!
by Dave Buchholz, 1 year ago
print $handle->file_src_mime; show that it is transferred as text/plainReply
Re: SVG Images new!
by Dave Buchholz, 1 year ago
here is the log:
system information
- class version : 0.35dev
- operating system : Darwin
- PHP version : 5.6.30
- GD version : 2.1.0
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 15M (15728640 bytes)
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
    MAGIC path will not be used
    MIME type detected as text/plain; charset=us-ascii by Fileinfo PECL extension
- MIME validated as text/plain
source variables
- You can use all these before calling process()
    file_src_name : M-Search-Icon.svg
    file_src_name_body : M-Search-Icon
    file_src_name_ext : svg
    file_src_pathname : /private/var/tmp/phpECyHvr
    file_src_mime : text/plain
    file_src_size : 471 (max= 15728640)
    file_src_error : 0
process file to ../../uploads/slides/kitchen/
- file size OK
- script renamed as M-Search-Icon.svg.txt!
- file mime OK : text/plain
- file name safe format
- destination variables
    file_dst_path : ../../uploads/slides/kitchen/
    file_dst_name_body : M-Search-Icon.svg
    file_dst_name_ext : txt
- checking for auto_rename
- destination file details
    file_dst_name : M-Search-Icon.svg.txt
    file_dst_pathname : ../../uploads/slides/kitchen/M-Search-Icon.svg.txt
- M-Search-Icon.svg.txt doesn't exist already
- ../../uploads/slides/kitchen/ is not writeable. Attempting chmod: failed
- error: Destination directory can't be made writeable. Can't carry on a process.Reply
Re: SVG Images new!
by colin, 1 year ago
Your system doesn't detect MIME property. It should be image/svg+xml. You can try to deactivate MIME detection using FileInfo by setting mime_fileinfo to false in the function init() but best is to fix your system.Reply
Re: SVG Images new!
by Dave Buchholz, 1 year ago
ok, thanks I will look into thatReply
Re: SVG Images new!
by Dave Buchholz, 1 year ago
Just following this up, disabling mime_fileinfo gave me the correct file extension see log below but something that struck me was that when I did a print_r on $_FILES it has the correct mime type there ?

print_r($_FILES) gives Array
(
[src] => Array
(
[name] => cogs.svg
[type] => image/svg+xml
[tmp_name] => /usr/tmp/phpmyNgBK
[error] => 0
[size] => 3385
)

)

logs for this upload

system information
- class version : 0.35dev
- operating system : FreeBSD
- PHP version : 5.6.36
- GD version : 2.1.0
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 50M (52428800 bytes)
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
    MAGIC path will not be used
    MIME type detected as text/plain; charset=us-ascii by Fileinfo PECL extension
- MIME validated as text/plain
source variables
- You can use all these before calling process()
    file_src_name : cogs.svg
    file_src_name_body : cogs
    file_src_name_ext : svg
    file_src_pathname : /usr/tmp/phpmyNgBK
    file_src_mime : text/plain
    file_src_size : 3385 (max= 52428800)
    file_src_error : 0
process file to ../../uploads/slides/kitchen-test/
- file size OK
- script renamed as cogs.svg.txt!
- file mime OK : text/plain
- file name safe format
- destination variables
    file_dst_path : ../../uploads/slides/kitchen-test/
    file_dst_name_body : cogs.svg
    file_dst_name_ext : txt
- checking for auto_rename
- destination file details
    file_dst_name : cogs.svg.txt
    file_dst_pathname : ../../uploads/slides/kitchen-test/cogs.svg.txt
- cogs.svg.txt doesn't exist already
- ../../uploads/slides/kitchen-test/ doesn't exist. Attempting creation: failed
- error: Destination directory can't be created. Can't carry on a process.Reply
Re: SVG Images new!
by Dave Buchholz, 1 year ago
Ignore that last set of logs here are the correct ones, have 2 test files and chose the wrong one!

print_r($_FILES) = Array
(
[src] => Array
(
[name] => cogs.svg
[type] => image/svg+xml
[tmp_name] => /usr/tmp/phpr4j7ar
[error] => 0
[size] => 3385
)

)

Logs:
system information
- class version : 0.35dev
- operating system : FreeBSD
- PHP version : 5.6.36
- GD version : 2.1.0
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 50M (52428800 bytes)
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Fileinfo PECL extension deactivated
- Checking MIME type with UNIX file() command
    MIME type detected as image/svg; charset=us-ascii by UNIX file() command
- MIME validated as image/svg
source variables
- You can use all these before calling process()
    file_src_name : cogs.svg
    file_src_name_body : cogs
    file_src_name_ext : svg
    file_src_pathname : /usr/tmp/phpr4j7ar
    file_src_mime : image/svg
    file_src_size : 3385 (max= 52428800)
    file_src_error : 0
process file to ../../uploads/slides/kitchen-test/
- file size OK
- file mime OK : image/svg
- file name safe format
- destination variables
    file_dst_path : ../../uploads/slides/kitchen-test/
    file_dst_name_body : cogs
    file_dst_name_ext : svg
- checking for auto_rename
- destination file details
    file_dst_name : cogs.svg
    file_dst_pathname : ../../uploads/slides/kitchen-test/cogs.svg
- cogs.svg doesn't exist already
- ../../uploads/slides/kitchen-test/ doesn't exist. Attempting creation: failed
- error: Destination directory can't be created. Can't carry on a process.Reply
Re: SVG Images new!
by colin, 1 year ago
The MIME type in $_FILES is sent by the client, and cannot be trusted. It is used only if all the server-side MIME detections fail.Reply
Re: SVG Images new!
by Dave Buchholz, 1 year ago
ok, that makes sense

thanksReply