Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ffmpeg文件名可变php中转义单个qoute_Php_Ffmpeg_Escaping - Fatal编程技术网

在ffmpeg文件名可变php中转义单个qoute

在ffmpeg文件名可变php中转义单个qoute,php,ffmpeg,escaping,Php,Ffmpeg,Escaping,代码工作正常,但如果文件名只有一个qoute,就像“Britney's video.mp4”一样,它就不工作了 $ffmpeg = "/usb/bin/local/ffmpeg"; $videos = "/videos/*.mp4"; $ouput_path = "/videos/thumbnails/"; foreach(glob($videos) as $video_file){ $lfilename = basename($video_file); $filename = basen

代码工作正常,但如果文件名只有一个qoute,就像“Britney's video.mp4”一样,它就不工作了

$ffmpeg = "/usb/bin/local/ffmpeg";
$videos = "/videos/*.mp4";
$ouput_path = "/videos/thumbnails/";


foreach(glob($videos) as $video_file){

$lfilename = basename($video_file);
$filename = basename($video_file, ".mp4");
$thumbnail = $ouput_path.$filename.'.jpg';
if (!file_exists($filename)) {
#$thumbnail = str_replace("'", "%27", $thumbnail);
exec("/usr/local/bin/ffmpeg -i '$video_file' -an -y -f mjpeg -ss 00:00:30 -vframes 1 '$thumbnail'");
}
echo "<a href='$lfilename'>$filename<img src='thumbnails/$filename.jpg' width='350'>";
$ffmpeg=“/usb/bin/local/ffmpeg”;
$videos=“/videos/*.mp4”;
$ouput_path=“/videos/thumbnails/”;
foreach(glob($videos)作为$video\u文件){
$lfilename=basename($video\u文件);
$filename=basename($video_文件,.mp4”);
$thumbnail=$output_path.$filename.'.jpg';
如果(!file_存在($filename)){
#$thumbnail=str_replace(“'”、“%27”、$thumbnail);
exec(“/usr/local/bin/ffmpeg-i'$video_file'-an-y-f mjpeg-ss 00:00:30-vframes 1'$thumbnail'”);
}
回显“$filename”;

正如注释中所建议的,您只需将所有shell命令字符串包装在
escapeshellarg()
中,如下所示

<?php

    foreach(glob($videos) as $video_file){
        $lfilename = basename($video_file);
        $filename  = basename($video_file, ".mp4");
        $thumbnail = $ouput_path.$filename.'.jpg';

        if (!file_exists($filename)) {
            $cmd         = "/usr/local/bin/ffmpeg -i ";
            $cmd        .= $video_file . " -an -y -f mjpeg -ss 00:00:30 ";
            $cmd        .= "-vframes 1 " . $thumbnail;

            exec( escapeshellarg($cmd) );
        }

我让它工作了,但没有使用过于复杂的东西。
谢谢大家

$comd = "/usr/local/bin/ffmpeg -i \"$video_file\" -y -f mjpeg -ss 00:00:30 -vframes 1 \"$thumbnail\" 2>&1"; shell_exec($comd);
shell_exec($comd);

您可以在
$video\u文件
$thumbnail
上使用。谢谢,我不知道如何使用或放置它。只是看起来太复杂了。单击提供的链接了吗?它解释了它的功能。
escapeshellarg()在字符串周围添加单引号,并引用/转义任何现有的单引号,允许您将字符串直接传递给shell函数,并将其视为单个安全参数。
谢谢,我确实访问了它,但我不知道将其放置在何处……或如何放置。您了解手册页上的内容/您的代码在做什么吗?您在哪里你挂断了吗?如果我将escapeshellarg删除到exec($cmd)),它可以工作,但仍然不能与“例如布兰妮的视频”的文件名一起工作。我使用$comd=“/usr/local/bin/ffmpeg-i\”$video\u file\”-y-f mjpeg-ss 00:00:30-vframes 1\“$thumbnail\”2>&1”shell\u exec($comd);但我怎样才能让它成为glob mp4s,avi而不仅仅是mp4?谢谢