I have a script for uploading files to my site. It works great but now I'm wanting to extract meta data from video files using the ffmpeg/ffprobe library. My code:
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);
}
}
I wind up with this error:
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>
I have passed the ffmpeg library the absolute path to ffprobe so it knows where it is. I was searching around and some people were saying this is because the lib can't access the tmp directory with the uploaded file. In either case, I've been trying to disable open_basedir
or at least add the paths I need to it to get this to work.
I tried setting open_basedir
to none in my php.ini
but it didn't work. When I view phpinfo()
, it still lists a bunch of paths for that setting. I tried to grep where open_basedir
exists on the server. Indeed, it's the php.ini
files and I shouldn't need to modify any other than the one reported in phpinfo()
.
I fixed it. For some reason, grep wasn't returning all files with the
basedir
string. I had to edit the php-fpm file for the specific site:/etc/php/7.0/fpm/pool.d/web8.conf
and append the paths:/usr/bin/ffmpeg:/usr/bin/ffprobe
to the
php_admin_value[open_basedir]
directive. Thensystemctl reload php7.0-fpm.service
and done.