note 92522 modified in function.curl-setopt by danbrown

From: Date: Tue, 28 Jul 2009 13:37:29 +0000
Subject: note 92522 modified in function.curl-setopt by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158819@lists.php.net to get a copy of this message
When you are using CURLOPT_FILE to download directly into a file you must close the file handler after the curl_close() otherwise the file will be incomplete and you will not be able to use it until the end of the execution of the php process. <?php $fh = fopen('/tmp/foo', 'w'); $ch = curl_init('http://example.com/foo'); curl_setopt($ch, CURLOPT_FILE, $fh); curl_exec($ch); curl_close($ch); # at this point your file is not complete and corrupted fclose($fh); # now you can use your file; read_file('/tmp/foo'); ?> --was-- When you are using CURLOPT_FILE to download directly into a file you must close the file handler after the curl_close() otherwise the file will be incomplete and you will not be able to use it until the end of the execution of the php process. <?php $fh = fopen('/tmp/foo', 'w'); $ch = curl_init('http://foo.bar/foo'); curl_setopt($ch, CURLOPT_FILE, $fh); curl_exec($ch); curl_close($ch); # at this point your file is not complete and corrupted fclose($fh); # now you can use your file; read_file('/tmp/foo'); ?> http://php.net/manual/en/function.curl-setopt.php

« previous php.notes (#158819) next »