/*
**功能:获取远程文件的大小,返回值的单位是:字节
*/
function
get_fileSize($url){
if(!isset($url)||trim($url)==''){
return
''
}
ob_start()
$ch=curl_init($url)
curl_setopt($ch,CURLOPT_HEADER,1)
curl_setopt($ch,CURLOPT_NOBODY,1)
$okay=curl_exec($ch)
curl_close($ch)
$head=ob_get_contents()
ob_end_clean()
$regex='/Content-Length:\s([0-9].+?)\s/'
$count=preg_match($regex,$head,$matches)
return
isset($matches[1])&&is_numeric($matches[1])?$matches[1]:''
}
希望本文所述对大家的php程序设计有所帮助,大家能够喜欢小便的文章,大家共同进步。
1、用file_get_contents或者fopen、file、readfile等函数读取url的时候,会创建一个名 为$http_response_header的变量来保存http响应的报头.示例代码一:
[php] view plain copy <?php $url = 'http://www.baidu.com' $html = file_get_contents($url) print_r($http_response_header) //输出结果 Array( [0] => HTTP/1.1 200 OK [1] => Date: Tue, 06 Nov 2012 08:51:01 GMT [2] => Server: BWS/1.0 [3] => Content-Length: 9803 [4] => Content-Type: text/htmlcharset=gbk [5] => Cache-Control: private [6] => Expires: Tue, 06 Nov 2012 08:51:01 GMT [7] => Set-Cookie: BAIDUID=6635735B51B28640F425F802C49340F2:FG=1 expires=Tue, 06-Nov-42 08:51:01 GMT path=/ domain=.baidu.com [8] => P3P: CP=" OTI DSP COR IVA OUR IND COM " [9] => Connection: Close ) ?> 2、使用fopen等函数打开的数据流信息可以用 stream_get_meta_data来获取。示例代码二:[php] view plain copy <?php $fp = fopen($url, 'r') print_r(stream_get_meta_data($fp)) fclose($fp) //输出结果 Array ( [wrapper_data] => Array ( [0] => HTTP/1.1 200 OK [1] => Date: Tue, 06 Nov 2012 08:54:22 GMT [2] => Server: BWS/1.0 [3] => Content-Length: 9803 [4] => Content-Type: text/htmlcharset=gbk [5] => Cache-Control: private [6] => Expires: Tue, 06 Nov 2012 08:54:22 GMT [7] => Set-Cookie: BAIDUID=347578BCBD709F27925BDD8B05364A73:FG=1 expires=Tue, 06-Nov-42 08:54:22 GMT path=/ domain=.baidu.com [8] => P3P: CP=" OTI DSP COR IVA OUR IND COM " [9] => Connection: Close ) [wrapper_type] => http [stream_type] => tcp_socket [mode] => r [unread_bytes] => 0 [seekable] => [uri] => http://www.baidu.com [timed_out] => [blocked] => 1 [eof] => ) ?> 3、get_headers()也可以获取请求url的响应报文。示例代码三:[html] view plain copy <?php print_r(get_headers($url)) Array ( [0] => HTTP/1.1 200 OK [1] => Date: Tue, 06 Nov 2012 08:58:41 GMT [2] => Server: BWS/1.0 [3] => Content-Length: 9803 [4] => Content-Type: text/htmlcharset=gbk [5] => Cache-Control: private [6] => Expires: Tue, 06 Nov 2012 08:58:41 GMT [7] => Set-Cookie: BAIDUID=87B6F26EEC74F2B8F7FABA934DC6BB24:FG=1 expires=Tue, 06-Nov-42 08:58:41 GMT path=/ domain=.baidu.com [8] => P3P: CP=" OTI DSP COR IVA OUR IND COM " [9] => Connection: Close ) ?> 4、php5中新增的参数context使这些函数更加灵活,通过它我们可以定制http请 求,甚至post数据。
默认只能传最大 2M 的文件。不过,可以配置php.ini文件,修改上传文件大小的限制。
配置php.ini文件 (以上传500M以下大小的文件为例)
查找以下选项并修改->
file_uploads = On 打开文件上传选项
upload_max_filesize = 500M 上传文件上限
如果要上传比较大的文件,仅仅以上两条还不够,必须把服务器缓存上限调大,把脚本最大执行时间变长
post_max_size = 500M post上限
max_execution_time = 1800 Maximum execution time of each script, in seconds脚本最大执行时间
max_input_time = 1800 Maximum amount of time each script may spend parsing request data
memory_limit = 128M Maximum amount of memory a script may consume (128MB)内存上限
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)