mogrify resize file name with bracket

ε祈祈猫儿з 提交于 2020-01-17 01:49:07

问题


in php it failed when resize file name that include "(" bracket.

normally I do

exec("mogrify -resize {$filewidth}x{$fileheight}! \"$file\"");

but it don't work with filename with bracket

by command line have to escape like this for working.

mogrify -resize 203x126! 53v-slave-only\(2\).png

how to fix it for php by exec() command

note filename must use bracket.

thank you.


回答1:


Try to use escapeshellcmd and escapeshellarg when using functions that works with the command line.

For example:

<?php
$filewidth = escapeshellcmd($filewidth);
$fileheight = escapeshellcmd($fileheight);
$file = escapeshellcmd($file);

exec("mogrify -resize {$filewidth}x{$fileheight}! \"$file\"");
?>



回答2:


$file=str_replace(array('(',')'),array('\\(','\\)'),$file);


来源:https://stackoverflow.com/questions/6881777/mogrify-resize-file-name-with-bracket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!