PHP file_get_contents with zip://: failed to open stream: operation failed
<p>I'm trying to read a file from a ZIP archive with the <code>zip://</code> steam operator. This file has been downloaded from the internet. My code is as follows:</p>

<pre><code>$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);
</code></pre>

<p>The error is as follows:</p>

<pre><code>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
</code></pre>

<p>I'm sure it's not a permissions issue since I give 777 permissions on the file, the directory this all happens in has 777 permissions (recursively) and the error doesn't say so. If <code>file_get_contents()</code> can't read it because of bad permissions, it'll say <code>failed to open stream: Permission denied</code>. </p>

<p>I'm also sure the file exists. I can obviously see it when I unzip the file manually and if it doesn't, <code>file_get_contents()</code> should say <code>failed to open stream: No such file or directory</code>. </p>

<p>The archive also isn't corrupt, I can unzip it manually just fine. This all runs on a Mac (macOS 10.12 Sierra). </p>

<p>PHP Version information:</p>

<pre><code>$: 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
</code></pre>