★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.filesize.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to ファイルシステム
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
ファイルシステム
* basename
* chgrp
* chmod
* chown
* clearstatcache
* copy
* delete
* dirname
* diskfreespace
* fclose
* feof
* fgetc
* fgetcsv
* fgets
* fgetss
* file
* file_exists
* fileatime
* filectime
* filegroup
* fileinode
* filemtime
* fileowner
* fileperms
* filesize
* filetype
* flock
* fopen
* fpassthru
* fputs
* fread
* fscanf
* fseek
* fstat
* ftell
* ftruncate
* fwrite
* set_file_buffer
* is_dir
* is_executable
* is_file
* is_link
* is_readable
* is_writeable
* link
* linkinfo
* mkdir
* pclose
* popen
* readfile
* readlink
* rename
* rewind
* rmdir
* stat
* lstat
* realpath
* symlink
* tempnam
* touch
* umask
* unlink
Manual: filesize
View the source code for this pageSearch the site



Previous page
 fileperms
 Updated
Sat, 12 Aug 2000
filetype 
Next page


filesize

(PHP3 , PHP4 )

filesize -- ファイルのサイズを取得する

説明

int filesize (string filename)

ファイルのサイズを返し、エラーの場合はfalseを返します。

この関数の結果はキャッシュされます。詳細は、 clearstatcache()を参照下さい。


User Contributed Notes: filesize


jdavis@genesiswd.com
19-Dec-1999 07:06

here is some sample code to retrieve the size of an image and then save the image to disk, from a web server.

$imgDir = "/home/httpd/upload/new.gif"; // save new gif here
$imgPath = '/foo/bar.gif'; // remote location
$imgHost = "www.foo.com";
$fp = fsockopen($imgHost, 80, &$errno, &$errstr, 30);
if(!$fp) {
echo "ERROR: $errno: $errstr";
} else {
fputs($fp,"HEAD $imgPath HTTP/1.0\nHost: $imgHost\n\n");
while(!feof($fp)) {
$response .= fgets($fp,128);
}
fclose($fp);
}
$imgSz = ereg_replace("(.*)(Content-Length: )([0-9]*)(.*)","\\3",$response);
$file = fopen($imgPath,"br"); // open external gif in binary mode and RO
$contents = fread( $file, $imgSz );
fclose($file);
$file2 = fopen($imgDir,"wb"); // open new local file in bin/write mode
fwrite($file2,$contents,$imgSz);
fclose($file2);



jesse@jess.on.ca
28-Jan-2000 07:37
here's a nifty thing to have the filesize rounded to 2 decimals, AND display size in bytes/kilo/meg/gig depending on filesize..
(dunno if this could be cut down, but it's at least a start)
--- cut ---
<pre>
$file_size = filesize(<FILENAME>);
if ($file_size >= 1073741824) {
$file_size = round($file_size / 1073741824 * 100) / 100 . "g";
} elseif ($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . "m";
} elseif ($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 . "k";
} else {
$file_size = $file_size . "b";
}
</pre>
--- end cut ---

have fun with this..

jesse.

mail, jesse@jess.on.ca
http, www.jess.on.ca



kris@toolhouse.com
09-Mar-2000 01:19
the max_file_size problem you're having can be resolved by making sure that a) your max_file_size var in your form upload is set correctly and b) PHP is configured for upload_max_filesize to be at least that large. The default PHP config is 2MB. By adding or changing a line in the php3.ini, or your apache.conf directives you should be able to fix your problem.


sheepcow@neorift.net
19-Mar-2000 06:01
hi, can you email replies please. :)
Can filesize(); check the files size of a file ON A REMOTE SERVER?

Cheers



coleman911@yahoo.com
13-May-2000 08:51
As far as I can see, you cannot view the filesize of objects on remote servers. If anyone knows any differently, please post, I'd love to know how.


jm@cybercity.dk
15-May-2000 08:05
Why does <PRE>$thesize = filesize($url);</PRE> not work on http:// urls? - And wouldn't it be a cool feature to have in PHP4???



seb@50carleton.com
14-Jul-2000 04:59
About finding the file size of a remote file, I highly doubt that you could access this kind of information on a remote machine. This would be a huge security issue. If you really want to find the size of a file on a remote web server, you could write a socket script to connect to the desired HTTP server and by sending:



HEAD /filefolder/file.jpg HTTP/1.1&lt;CRLF&gt;

Host: www.yourhostname.com&lt;CRLF&gt;&lt;CRLF&gt;



Then the webserver should send you the header of that file which contains the header field "Content-Length: ". It's value is the size of the file requested. Note that you need the "Host: " header field if you specify HTTP version 1.1 (HTTP/1.1) or the server will respond with an error. Also, the command HEAD is not supported by all servers. You can use GET instead, but the server will send the header with the file content which will take longer to process.



Check the HTTP RFC for more info on the protocol. If the file is not on a web server, then your on your own. ;)



Seb




14-Jul-2000 06:25
nfs anyone? :-)


andygui@yahoo.com
14-Jul-2000 06:35
Is there a way, through PHP to add up the size of all the files without:
1. using echo `du -sk` and
2. looping through an array of files and calling the filesize() function over and over.



tim@isdebaas.nl
15-Jul-2000 12:53
About the filesize checking on a remote server:



I don't know how to do it and if it's possible (I doubt it)... But how does my browser it when downloading a file? When I download a file it always says something like "1,58Mb of 2,79Mb completed"? Anyone?



jan@webii.dk
26-Jul-2000 04:53
I think it is a heading, sometimes it does not write the size, maybe because the server does not send the size.


npoole@binary.net
28-Jul-2000 08:03
Method of checking if a file is empty.



$file="$LLQE_$date.txt";


$header = fopen("$file","a+");


if (filesize($file)==0) {


echo "The file is empty";

}
I had some trouble with it at first.




08-Aug-2000 03:01
I try to display the download file in KB but its display like 24,450 MB.


noper
10-Aug-2000 09:25
This might help for filesize on a remote server.. from faqts.com

<pre>
Loop using fread and check for eof with a predefined buffersize (example using 1000 bytes buffer)

$fp = fopen ($picture_name, "r");
while (!feof($fp))
{
$contents .= fread($fp, 1000);
}
fclose($fp);

print "filseize: " . strlen($contents) . "
";

$fp2 = fopen ("c:/temp/test.gif","w");
fwrite($fp2,$contents,strlen($contents));
fclose($fp2);
</pre>




10-Aug-2000 03:38
macam mana nih????????


 About Notes


Previous page
 fileperms
 Updated
Sat, 12 Aug 2000
filetype 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.