PHP escapeshellcmd()使用'>'字符打破ImageMagick转换命令(PHP escapeshellcmd() breaks ImageMagick convert command using '>' character)
我在Ubuntu 12服务器上使用ImageMagick 6.6.9。 我遇到的问题是我的ImageMagick转换命令,我使用
shell_exec
函数运行PHP(但也尝试过exec
),其中包含PHPescapeshellcmd
函数转义的字符\
这是我的PHP代码:
$result = exec(escapeshellcmd($convertString));
这是我的示例转换命令:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail "640x88>" "/Users/rich/Sites/example/1234-thumb.jpg"
最后这里是转换命令,它通过
escapeshellcmd
运行:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail "640x88\>" "/Users/rich/Sites/example/1234-thumb.jpg"
问题是转义的
\>
字符会导致ImageMagick错误:convert:选项-thumbnail的无效参数':640x88> @ error / convert.c / ConvertImageCommand / 2770。
有谁知道我能解决这个问题的方法吗? 我已经搜索了ImageMagick文档,当他们确认问题时,他们似乎没有提供任何其他方法来调整图像大小而不使用特殊的unix字符:
唯一收缩标志('>'标志)是UNIX Shell和Window批处理脚本中的特殊字符,您需要转义该字符(在shell中使用反斜杠'>',在Windows批处理中使用'^>') 。 它也是HTML网页中的特殊内容,因此PHP脚本也可能需要一些特殊处理。
提前谢谢了。
I'm using ImageMagick 6.6.9 on an Ubuntu 12 server. The problem I have is that my ImageMagick convert command, which I run through PHP using the
shell_exec
function (but have also triedexec
), has characters in it which the PHPescapeshellcmd
function escapes with a\
Here is my PHP code:
$result = exec(escapeshellcmd($convertString));
Here is my sample convert command:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail "640x88>" "/Users/rich/Sites/example/1234-thumb.jpg"
And finally here is the convert command after it has been run through
escapeshellcmd
:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail "640x88\>" "/Users/rich/Sites/example/1234-thumb.jpg"
The problem is that the escaped
\>
character results in an ImageMagick error:convert: invalid argument for option -thumbnail': 640x88> @ error/convert.c/ConvertImageCommand/2770.
Does anyone know of a way that I can get around this? I have trawled the ImageMagick documentation and while they acknowledge the problem they don't seem to provide any other way of resizing an image without using the special unix characters:
The Only Shrink Flag ('>' flag) is a special character in both UNIX Shell and in Window batch scripts, and you will need to escape that character (using backslash '>' in shell, and '^>' in windows batch). It is also special in and HTML web pages, so PHP scripts also may need some special handling.
Many thanks in advance.
原文:https://stackoverflow.com/questions/14477401
最满意答案
如果您的目标是在用户单击链接时隐藏div,则无需使用某些奇特的查询字符串重新加载整个页面。 只需在单击链接时调用javascript函数:
<div id='hide-me'>This is the div you want to hide</div> <a href='#' onclick='hideTheDiv()'>hide something</a> <script type='text/javascript'> function hideTheDiv() { $('#hide-me').hide(); } </script>
对于您的信息,
href='#'
告诉HTML不要重新加载页面或去任何地方。 所以页面保持原样。 onclick告诉HTML运行一个javascript函数。听起来你有一些学习要做的事情。 结帐这些资源: http : //www.w3schools.com/jsref/event_onclick.asp (也可以应用于锚标签,而不仅仅是按钮) http://www.w3schools.com/jquery/jquery_ref_selectors.asp
if your goal is to have a div hide when the user clicks a link, there's no need to reload the whole page with some fancy querystring. Just call a javascript function when the link is clicked:
<div id='hide-me'>This is the div you want to hide</div> <a href='#' onclick='hideTheDiv()'>hide something</a> <script type='text/javascript'> function hideTheDiv() { $('#hide-me').hide(); } </script>
For your info, the
href='#'
tells HTML not to reload the page or go anywhere. so the page stays where it is. onclick tells HTML to run a javascript function.Sounds like you've got some learning to do. checkout these resources: http://www.w3schools.com/jsref/event_onclick.asp (can be applied to an anchor tag too, not just buttons) http://www.w3schools.com/jquery/jquery_ref_selectors.asp
相关问答
更多-
HTML不规则 ,所以你不应该使用正则表达式。 相反,我会推荐一个HTML解析器,如简单的HTML DOM或DOM 如果你打算使用简单的HTML DOM,你可以做如下的事情: $html = str_get_html($file_contents); $elem = $html->find('div[id=wrapper_content]', 0); 即使你使用正则表达式,你的代码仍然无法正常工作。 在使用正则表达式之前,您需要获取页面的内容。 //wrong if(!preg_match($s_sear ...
-
用于隐藏网页上特定div的URL /地址条形码[关闭](URL/address bar code to hide a specific div on the webpage [closed])[2023-07-26]
如果您的目标是在用户单击链接时隐藏div,则无需使用某些奇特的查询字符串重新加载整个页面。 只需在单击链接时调用javascript函数:This is the div you want to hidehide something 要么