【发布时间】:2014-06-21 02:48:30
【问题描述】:
我有一个 ffmpeg 转换器,可以将视频转换为 mp4。转换后我想删除原始视频以节省文件空间。
我尝试使用unlink($file_path),但它说权限被拒绝。
到目前为止,视频转换并生成转换后的缩略图。
$ffmpeg = 'ffmpeg';
$output = dirname(__DIR__).'/uploads/thumbs/'.$_file.'.jpg';
$input = dirname(__DIR__).'/uploads/'.$file;
$mov = new ffmpeg_movie($input);
$d = $mov->getDuration();
$iscopy = $mov->getCopyright();
$h = $mov->getFrameHeight();
$w = $mov->getFrameWidth();
$pos = ceil((int)$d /3);
$size = $w.'x'.$h;
$i = explode('.',$input);
$o = $i[0].'.mp4';
if(ceil($d) < 1200){
if($ext != 'mp4'){
$cmd = "ffmpeg -i $input -vcodec h264 -acodec aac -strict -2 $o";
shell_exec($cmd);
}
$cmd = "ffmpeg -ss $pos -i $o -an -s $size $output";
shell_exec($cmd);
$total_time += $pos;
$succedeed[] = array('name' => $name,'file' => 'thumbs/'.$_file.'.jpg', 'type' => 'mp4');
if(file_exists('../uploads/'.$file)){
unlink('../uploads/'.$file);
}
}else{
$failed[] = array('name' => $name, 'file' => $file, 'error' => 'Video length cannot exceed 20mins.');
}
文件的路径是这样的:
unlink(../uploads/fdbc716e18173d4fe895c6d0b03365df1399237360.avi)
我尝试了this (question)、this (question) 和很多谷歌搜索,但没有成功:
chdir($FilePath); // Comment this out if you are on the same folder
chown($FileName,465); //Insert an Invalid UserId to set to Nobody Owner; for instance 465
$do = unlink($FileName);
if($do=="1"){
echo "The file was deleted successfully.";
} else { echo "There was an error trying to delete the file."; }
【问题讨论】: