3 solutions to get remote file size in PHP_PHP Tutorial
Jul 21, 2016 pm 03:00 PM
file
get
p
php
code
use
copy
big
document
method
Obtain
solve
Remotely
1. Use file_get_contents()
Copy the code The code is as follows:
<?php
$file = file_get_contents($url);
echo strlen($file);
?>
2. Use get_headers()
Copy code The code is as follows:
<?php
$header_array = get_headers($url, true);
$size = $header_array['Content-Length'];
echo $size;
?>
PS:
required Open allow_url_fopen!
If it is not opened, it will be displayed
Warning: get_headers() [function.get-headers]: URL file-access is disabled in the server configuration
3. Use fsockopen ()
Copy code The code is as follows:
<?php
function get_file_size($url) {
$url = parse_url($url);
if (empty($url['host'])) {
return false;
}
$ url['port'] = empty($url['post']) ? 80 : $url['post'];
$url['path'] = empty($url['path']) ? '/' : $url['path'];
$fp = fsockopen($url['host'], $url['port'], $error);
if ($fp) {
host']. "rnrn");
while (!feof($fp)) {
$str = fgets($fp);
if (trim($str) == ' ') {
break;
}elseif(preg_match('/Content-Length:(.*)/si', $str, $arr)) {
return trim($arr[1]) ;
; 🎜> }
?>
http://www.bkjia.com/PHPjc/328048.html
www.bkjia.com
http: //www.bkjia.com/PHPjc/328048.html
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
