简体   繁体   English

PHP $ _FILE临时位置open_basedir冲突PHP-FPM / Nginx

[英]PHP $_FILE Temp Location open_basedir Conflict PHP-FPM/Nginx

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 . 效果很好,但是现在我想使用ffmpeg / ffprobe库从视频文件中提取元数据。 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. 我已经将ffmpeg库传递给ffprobe的绝对路径,因此它知道它在哪里。 I was searching around and some people were saying this is because the lib can't access the tmp directory with the uploaded file. 我到处搜索,有人说这是因为lib无法使用已上传的文件访问tmp目录。 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. 无论哪种情况,我都试图禁用open_basedir或至少添加我需要的路径才能使其正常工作。

I tried setting open_basedir to none in my php.ini but it didn't work. 我尝试在php.ini中将open_basedir设置为none,但是没有用。 When I view phpinfo() , it still lists a bunch of paths for that setting. 当我查看phpinfo() ,它仍然列出了该设置的一堆路径。 I tried to grep where open_basedir exists on the server. 我试图grep服务器上存在open_basedir的位置。 Indeed, it's the php.ini files and I shouldn't need to modify any other than the one reported in phpinfo() . 确实,这是php.ini文件,除了phpinfo()报告的文件外,我不需要修改任何文件。

I fixed it. 我修好了它。 For some reason, grep wasn't returning all files with the basedir string. 由于某些原因,grep不会返回所有带有basedir字符串的文件。 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: 我必须编辑特定站点的php-fpm文件: /etc/php/7.0/fpm/pool.d/web8.conf并添加路径:

/usr/bin/ffmpeg:/usr/bin/ffprobe

to the php_admin_value[open_basedir] directive. php_admin_value[open_basedir]指令。 Then systemctl reload php7.0-fpm.service and done. 然后systemctl reload php7.0-fpm.service并完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM