note 96903 modified in function.curl-setopt by dm

From: Date: Thu, 31 Jan 2013 20:31:27 +0000
Subject: note 96903 modified in function.curl-setopt by dm
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193470@lists.php.net to get a copy of this message
If you wish to find the size of the file you are streaming and use it as your header this is how: <?php function write_function($curl_resource, $string) { if(curl_getinfo($curl_resource, CURLINFO_SIZE_DOWNLOAD) <= 2000) { header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Description: File Transfer'); header("Content-Transfer-Encoding: binary"); header("Content-Type: ".curl_getinfo($curl_resource, CURLINFO_CONTENT_TYPE).""); header("Content-Length: ".curl_getinfo($curl_resource, CURLINFO_CONTENT_LENGTH_DOWNLOAD).""); } print $string; return mb_strlen($string, '8bit'); } ?> 1440 is the the default number of bytes curl will call the write function (BUFFERSIZE does not affect this, i actually think you can not change this value), so it means the headers are going to be set only one time. write_function must return the exact number of bytes of the string, so you can return a value with mb_strlen. --was-- If you wish to find the size of the file you are streaming and use it as your header this is how: <?php function write_function($curl_resource, $string) { if(curl_getinfo($curl_resource, CURLINFO_SIZE_DOWNLOAD) <= 2000) { header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Description: File Transfer'); header("Content-Transfer-Encoding: binary"); header("Content-Type: ".curl_getinfo($curl_resource, CURLINFO_CONTENT_TYPE).""); header("Content-Length: ".curl_getinfo($curl_resource, CURLINFO_CONTENT_LENGTH_DOWNLOAD).""); } print $string; return mb_strlen($string, '8bit'); } 1440 is the the default number of bytes curl will call the write function (BUFFERSIZE does not affect this, i actually think you can not change this value), so it means the headers are going to be set only one time. Writefunction must return the exact number of bytes of the string, so you can return a value with mb_strlen. ?> http://php.net/manual/en/function.curl-setopt.php

« previous php.notes (#193470) next »