带有zip://的PHP file_get_contents:无法打开流:操作失败

时间:2016-12-16 11:40:20

标签: php file permissions zip

我正在尝试使用zip:// Steam运算符从ZIP存档中读取文件。该文件已从互联网上下载。我的代码如下:

$url = 'https://example.com/file.zip';
file_put_contents(getcwd().'/temp.zip', fopen($url, 'r'));
chmod(getcwd() . '/temp.zip', 777);

$fileName = 'FILE_IN_ZIP.xml';
$data = file_get_contents('zip://' .  realpath('temp.zip') . '#' . $fileName);

错误如下:

PHP Warning:  file_get_contents(zip://path/to/temp.zip#FILE_IN_ZIP.xml): failed to open stream: operation failed in /my/project/directory/test.php on line 10

我确定这不是权限问题,因为我对该文件赋予了777权限,这一切都发生的目录具有777权限(递归)并且错误没有这样说。如果由于权限错误导致file_get_contents()无法读取,则会说failed to open stream: Permission denied

我也确定文件存在。我可以在手动解压缩文件时看到它,如果没有,file_get_contents()应该说failed to open stream: No such file or directory

存档也没有损坏,我可以手动解压缩就好了。这一切都在Mac(macOS 10.12 Sierra)上运行。

PHP版本信息:

$: php --version
PHP 7.0.3 (cli) (built: Feb  6 2016 03:16:24) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

0 个答案:

没有答案