代碼工作正常,但如果文件名只有一個qoute就像「Britney's video.mp4」一樣無效。在ffmpeg文件名變量中轉義單個qoute php
$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'>";
你可以使用http://php.net/manual/en/function.escapeshellarg.php上'$ video_file'和'$ thumbnail'。 – chris85
謝謝,我不知道如何使用它或把它。只是似乎過於複雜.. – DOMDocumentVideoSource
點擊鏈接提供?它解釋了它的作用。 'escapeshellarg()在字符串周圍添加單引號,並引號/轉義任何現有的單引號,允許您將字符串直接傳遞給shell函數,並將其視爲單個安全參數。「#: – chris85