文件问题包含空格和单引号?

时间:2010-03-22 09:47:09

标签: php file ffmpeg

我使用以下代码使用ffmpeg创建缩略图,但它对没有空格或任何引号的文件工作正常..

但是当文件有空格(如'sachin knock.flv')或带引号的文件(如sachin's_double_cent.mp4)时,它不起作用..

如何让这些文件准确运行?一个限制是我不能重命名文件,因为它们是一些...

我的代码是

<?php
    error_reporting(E_ALL);
    extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
    $link = mysql_connect('localhost', 'root', '');
    if (!$link) {
        die('Not connected : ' . mysql_error());
    }
    $db_selected = mysql_select_db('db', $link);

    $max_width  = 120;
    $max_height = 72;
    $path ="/home/rootuser/public_html/temp/";
    $qry="select id, input_file, output_file from videos where thumbnail='' or thumbnail is null;";
    $res=mysql_query($qry);
    while($row = mysql_fetch_array($res,MYSQL_ASSOC))
    {
        $orig_str = array(" ");
        $rep_str  = array("\ ");
        $outfile  = $row[output_file];
//      $infile   = $row[input_file];
        $infile1  = str_replace($orig_str, $rep_str, $outfile);

        $tmp      = explode(".",$infile1);
        $tmp_name = $tmp[0];
        $imgname  = $tmp_name.".png";
        $srcfile  = "/home/rootuser/public_html/uploaded_vids/".$outfile;
            echo exec("ffmpeg -i ".$srcfile." -r 1 -ss 00:00:05 -f image2 -s 120x72 ".$path.$imgname);
        $nname = "./temp/".$imgname;
        $fileo = fopen($nname,"rb");
        if($fileo)
        {
        $imgData = addslashes(file_get_contents($nname));
        echo $imgdata;
        $qryy="update videos set thumbnail='{$imgData}' where input_file='$outfile'"; 
        $ress=mysql_query($qryy);
        }
        else
            echo "Could not open<br><br>";
        unlink('$nname');    
    }
?>

1 个答案:

答案 0 :(得分:2)

请注意,如果这些文件是由用户提供的,那么您的代码不仅不起作用,而且对代码注入也是开放的。

这可以通过escapeshellcmd()来解决。