Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP curl fails to download data when outputting to a file but ok when printing to stdout
    text
    copied!<p>This has been bugging me for literally hours already.</p> <p>I can't seem to figure out why PHP <strong>cURL won't download data to a file</strong>. (CURLOPT_FILE is set to a local file.) I am not getting any data. I periodically check the file size of the destination file and it is always zero. To give you a background, I am downloading a 90kb jpeg file (for testing purposes).</p> <p>This is working on my local computer (XP) but not in the website I am working on (Windows Server 2003).</p> <p>I did several tests which made the scenario even weirder.</p> <ol> <li><p><strong>I disabled CURLOPT_FILE to print the data returned by curl into standard output, and the binary data printed</strong>.</p></li> <li><p>Having experienced blocked websites before (since the server implements access control), I tried accessing the file from internet explorer and i was able to see it.</p></li> <li><p>Having experienced blocked downloads before, I tried downloading the file from internet explorer and it was downloaded.</p></li> <li><p>The file is created by fopen('', 'w') but the size remains 0. Despite this successful file creation, I thought maybe PHP has a problem with filesystem write privileges, I set the exe to be run even by non-admin users. Still no download.</p></li> </ol> <p>Has this ever occured to anybody?</p> <p>Any pointers will be appreciated. I am really stuck.</p> <p>Thank you.</p> <p>Here's the curl options I set:</p> <pre><code>$connection = curl_init($src); // If these are not set, curl_exec outputs data. // If these are set, curl_exec does not send any data to the file // pointed to by $file_handler. $file_handler is not null // because it is opened as write (non-existing file is created) curl_setopt($connection, CURLOPT_RETURNTRANSFER, true); curl_setopt( $connection, CURLOPT_FILE, $file_handler ); </code></pre> <p>PS: I'm doing these tests using the command line and not the browser.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload