我有一个用于将文件上传到我的网站的脚本。它工作得很好,但现在我想使用ffmpeg/ffprobe library从视频文件中提取元数据。我的代码:
if (!empty($_FILES)) {
$requestAr = requestCheck(['title', 'description']);
$assetName = randomString(11);
$assetSalt = randomString(3);
$bucket = "videos";
$fileTmpPath = $_FILES['qqfile']['tmp_name'];
$filenameOrig = $_FILES['qqfile']['name'];
$fileExtension = pathinfo($filenameOrig, PATHINFO_EXTENSION);
$assetFilename = $assetName . "_$assetSalt.$fileExtension";
$trustedExtensions = ['webm', 'mp4', 'ogg'];
if(array_search($fileExtension, $trustedExtensions) !== false) {
$ffprobe = FFMpeg\FFProbe::create([
'ffprobe.binaries' => '/usr/bin/ffprobe'
]);
$fileInfo = $ffprobe
->format($fileTmpPath) // extracts file informations
->get('duration'); // returns the duration property
print_r($fileInfo);
}
}
我结束了这个错误:
file_exists(): open_basedir restriction in effect. File(/usr/bin/ffprobe) is not within the allowed path(s): <lists all the directories in the open_basedir variable>
我已经将ffmpeg库传递给ffprobe的绝对路径,因此它知道它在哪里。我正在四处搜索,有些人说这是因为lib无法使用上传的文件访问tmp目录。在任何一种情况下,我一直在尝试禁用open_basedir
或至少添加我需要的路径以使其工作。
我尝试在open_basedir
中将php.ini
设置为无,但无效。当我查看phpinfo()
时,它仍会列出该设置的一系列路径。我试图grep服务器上存在open_basedir
的位置。实际上,它是php.ini
文件,我不应该修改phpinfo()
中报告的文件以外的任何文件。
答案 0 :(得分:0)
我修好了。出于某种原因,grep没有返回带有basedir
字符串的所有文件。我不得不编辑特定网站的php-fpm文件:/etc/php/7.0/fpm/pool.d/web8.conf
并附加路径:
/usr/bin/ffmpeg:/usr/bin/ffprobe
到php_admin_value[open_basedir]
指令。然后systemctl reload php7.0-fpm.service
并完成。