©
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
(PECL pecl_http >= 0.1.0)
http_send_file — Send file
$file
)Sends a file with support for (multiple) range requests.
This functions behaviour and further action is dependent on the following INI 设置s: http.send.not_found_404 和 http.log.not_found.
If the INI 设置 http.send.not_found_404
is enabled and the INI 设置 http.log.not_found
points to a writable file, a log message is written when the file
was not found.
file
the file to send
成功时返回 TRUE
, 或者在失败时返回 FALSE
。
Example #1 A http_send_file() example
<?php
http_send_content_disposition ( "document.pdf" , true );
http_send_content_type ( "application/pdf" );
http_throttle ( 0.1 , 2048 );
http_send_file ( "../report.pdf" );
?>
以上例程会输出:
HTTP/1.1 206 Partial Content X-Powered-By: PHP/5.2.2 Accept-Ranges: bytes Content-Length: 12345 Content-Range: bytes 0-12344 Content-Type: application/pdf Content-Disposition: inline; filename="document.pdf"%PDF...
[#1] dj [2015-03-31 14:16:39]
Above mentioned example is for version 1.
If you want an working example for v2 see devel-m6w6.rhcloud.com/mdref/http/Env/Response/setContentDisposition
Because windows.php.net/downloads/pecl/releases/http/ stores only v2 versions, all http plugin related function pages at php.net/manual/en/book.http.php should contain the following with big red bloody font:
THIS IS DOCUMENTATION FOR V1 WHICH WE DO NOT SUPPORT ANYMORE. SEE devel-m6w6.rhcloud.com/mdref/http FOR UPDATED DOCUMENTATION. Note: Functions are available by clicking subelements under http at tree which is positioned at right top position.
[#2] razzbee [2013-12-19 08:20:52]
<?php
http_send_content_disposition("document.pdf", true);
http_send_content_type("application/pdf");
http_throttle(0.1, 2048);
http_send_file("../report.pdf");
?>
None of the function above works with pecl_http 2.3 , I kept on getting Fatal error: Call to undefined function http_send_content_disposition() in xxxxxxx , I dont know ,but maybe its a bug in php 5.4 with centos 6.4 , The solution was just simple, I removed pecl_http 2.3 and installed Pecl_http package to 1.7.6 using the command below :
pecl remove pecl_http
pecl install http://pecl.php.net/get/pecl_http-1.7.6.tgz
[#3] Pieter [2013-01-07 12:57:42]
This function does not work together nicely with output buffering (ob_start etc.). If you get memory allocation errors, it probably means that you have got output buffering turned on and you should turn off output buffering.