Re: FW: looking for two remote functions
| From: | Myron Turner | Date: | Sat, 10 Mar 2007 12:41:57 +0000 |
| Subject: | Re: FW: looking for two remote functions | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-250202@lists.php.net to get a copy of this message | ||
Tijnema ! wrote:
On 3/10/07, Németh Zoltán <znemeth@alterationx.hu> wrote:I wrote a small perl script which returns the bytes read when a file is read from the disk and it, too, agrees with the filesize and header sizes. In Windows, the actual filesize is also returned by filesize and stat, not the size on disk (filesize uses stat). Also, in the PHP manual, the fread example uses filesize to set the number of bytes to read:2007. 03. 10, szombat keltezéssel 12.42-kor Riyadh S. Alshaeiq ezt írta:Actually if right click on any file or folder on a machine you willsee thatthere are two values (Size on disk & Size). Files and folders arestored onthe disk in what is called clusters (a group of disk sectors). Size ondiskrefers to the amount of cluster allocation a file is taking up,compared tofile size which is an actual byte count. As I mentioned before what I want is a function for getting the resultforthe Size no for Size on Diskokay then what about this? function real_filesize_linux($file) {He was interested on using it over HTTP, not over SSH... I don't know if there are faster ways, but you could open a socket to the host on port 80, get the file, and only read the header where it says content-length: 400 for example, then you know the file is 400bytes when you download it. something like: $socket = fsockopen($host,$port); $size = 0; while($size == 0) { $line = fgets($socket); if(strlen($line) >= 17) { if(substr(strtolower($line),0,14) == "content-length") { $size = substr($line,16) } } Now your remote file size is in $size. It is not too fast, but everything in PHP is fast and so is this. Tijnema Riyadh -----Original Message----- From: Németh Zolt?n [mailto:znemeth@alterationx.hu] Sent: 10/Mar/2007 12:27 PM To: Riyadh S. Alshaeiq Cc: php-general@lists.php.net Subject: Re: [PHP] FW: looking for two remote functions I'm afraid I don't understand what you want. The size of a file is its size in bytes, that is its size on the disk. So what else? greets Zolt?n Németh 2007. 03. 10, szombat keltezéssel 06.07-kor Riyadh S. Alshaeiq ezt@exec("filesize $file",$out,$ret); if ( $ret <> '0' ) return FALSE; else return($out[0]);} if you want it on a remote machine, you should use something like ssh2_exec() instead of exec() hope that helps Zoltán Németh?rta: Thank you Mickey, but I have already looked in there and the functionpostedin the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -----Original Message----- From: Mikey [mailto:frak@upcore.net] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote:needHello everybody, I am looking for an HTTP function for getting remote filesizes.Keeping inmind that I am NOT interested in getting the "size on disk"figure, Ithe actual size of the files when downloaded to a local machine.Please letme know if there are any.. Another thing, I also need a remote function that gets the createddate andlast modified separately, if possible.. Best regardsTry looking here: http://uk.php.net/manual/en/function.filesize.php If the function itself isn't of use to you, look further down in the notes and I am sure you will find something useful. Mikey-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpThis question has come up before, and out of curiosity I did some checking. If you use firefox liveheaders, it turns out that the file size on the linux file system is exactly the size shown in the content-length header. This is also the same size as returned by php's filesize() and by the php stat() in its size element. Linux reports the actual file size, not the storage size, which you can get by asking to see the number of blocks used to store the file (ls -ls).
| contents = fread($handle, filesize($filename));|The point of this is to read in the exact number of bytes for the file, not the entire size of the file's storage on disk which would contain garbage. This has to work on both windows and linux. Here's the perl script: use strict; use Fcntl; sysopen (FH, "index.htm", O_RDONLY); my $buffer; my $len = sysread(FH, $buffer, 8192,0); print $len,"\n"; If you are really anxious about size you can exec out to this script and get the file size. -- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/