mogrify 用括号调整文件名大小

发布于 2024-11-27 05:38:18 字数 351 浏览 6 评论 0原文

在 php 中,调整包含“(”括号的文件名大小时失败。

通常我会这样做,

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

但它不适用于

命令行中带括号的文件名,必须像这样转义才能工作。

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

如何通过exec()命令修复php的问题

注意文件名必须使用括号。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱格式化 2024-12-04 05:38:18

尝试使用 escapeshellcmdescapeshellarg 使用与命令行配合使用的函数时。

例如:

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

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

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\"");
?>
猫烠⑼条掵仅有一顆心 2024-12-04 05:38:18
$file=str_replace(array('(',')'),array('\\(','\\)'),$file);
$file=str_replace(array('(',')'),array('\\(','\\)'),$file);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文