Re: [PHP] FW: looking for two remote functions
Can you maybe explain why you want the exact size on the disk in blocks?? do you care if it differs 1KB?? what are you planning to write, the actual filesize on the disk can only differ 1 block with real filesize, and so if the blocksize is 1024bytes, it differes a max of 1024bytes... And btw, the size it takes on your server in blocks might be different then the size it takes on the server's disk... I'm not totally sure how a hdd works, but i know it is split up in blocks, and so you need to know the blocksize on the partition you are going to place the file, using different filesystems on 1 system can mean that a file is bigger/smaller on the same system. So the way to calculate the block filesize would be by getting the real filesize, and then round it until $filesize%$blocksize == 0 So, in PHP code it would like this. $blocksize = 1024; // Default on Ext2/3 i believe $filesize = filesize(http://server.com/file.rar;); while($filesize%$blocksize != 0) { $filesize += 1; } I'm not sure if it's the size you were looking for, but keep in mind that it depends on the block size. So different filesystems use different block size. Tijnema On 3/13/07, Richard Lynch [EMAIL PROTECTED] wrote: If PHP is returning that goofy Windows 'size on disk' number, I want to see your script... Because, no, I don't think it does that... On Sat, March 10, 2007 4:42 am, Riyadh S. Alshaeiq wrote: Actually if right click on any file or folder on a machine you will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk Riyadh -Original Message- From: Németh Zolt?n [mailto:[EMAIL PROTECTED] 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 ?rta: Thank you Mickey, but I have already looked in there and the function posted in the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote: Hello everybody, I am looking for an HTTP function for getting remote filesizes. Keeping in mind that I am NOT interested in getting the size on disk figure, I need the actual size of the files when downloaded to a local machine. Please let me know if there are any.. Another thing, I also need a remote function that gets the created date and last modified separately, if possible.. Best regards Try 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.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FW: looking for two remote functions
Just a little note, getting content-length and a lot of other stuff from remote files is also possbiel with curl_getinfo() www.php.net/curl_getinfo Tijnema On 3/11/07, Tijnema ! [EMAIL PROTECTED] wrote: Not everyone checks his email 1000 times a day, last time he replied was yesterday... so give him some time to read his email Tijnema On 3/11/07, Myron Turner [EMAIL PROTECTED] wrote: I think we've been talking to ourselves. The guy with the original question seems to have folded his hand and gone home. This is exactly what my script also did, get the content-length from the header. But i don't see what the actual problem is, there have been a lot of solutions around here but they are all wrong? Tijnema -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/
RE: [PHP] FW: looking for two remote functions
If PHP is returning that goofy Windows 'size on disk' number, I want to see your script... Because, no, I don't think it does that... On Sat, March 10, 2007 4:42 am, Riyadh S. Alshaeiq wrote: Actually if right click on any file or folder on a machine you will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk Riyadh -Original Message- From: Németh Zolt?n [mailto:[EMAIL PROTECTED] 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 ?rta: Thank you Mickey, but I have already looked in there and the function posted in the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote: Hello everybody, I am looking for an HTTP function for getting remote filesizes. Keeping in mind that I am NOT interested in getting the size on disk figure, I need the actual size of the files when downloaded to a local machine. Please let me know if there are any.. Another thing, I also need a remote function that gets the created date and last modified separately, if possible.. Best regards Try 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.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FW: looking for two remote functions
Myron Turner wrote: Tijnema ! wrote: On 3/10/07, Németh Zoltán [EMAIL PROTECTED] wrote: 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 will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk okay then what about this? Th 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: || 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. -- Sorry the above version of the script was hard-coded for a small test file. Here's the general version: # get_len.pl use strict; use Fcntl; sysopen (FH, $ARGV[0], O_RDONLY) or die \n; my $buffer; my $bytes_read = 0; my $offset; while($bytes_read = sysread(FH, $buffer, 8192, $offset)) { $offset+=$bytes_read ; } print $offset,\n; From an exec() you'd call it with the file name: perl get_len.pl filename $len = exec(perl get_len.pl $filename); _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FW: looking for two remote functions
On 3/11/07, Myron Turner [EMAIL PROTECTED] wrote: Myron Turner wrote: Tijnema ! wrote: On 3/10/07, Németh Zoltán [EMAIL PROTECTED] wrote: 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 will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk okay then what about this? Th 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: || 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. -- Sorry the above version of the script was hard-coded for a small test file. Here's the general version: # get_len.pl use strict; use Fcntl; sysopen (FH, $ARGV[0], O_RDONLY) or die \n; my $buffer; my $bytes_read = 0; my $offset; while($bytes_read = sysread(FH, $buffer, 8192, $offset)) { $offset+=$bytes_read ; } print $offset,\n; From an exec() you'd call it with the file name: perl get_len.pl filename $len = exec(perl get_len.pl $filename); I'm not very familiar with PERL, so will this work with remote files? As it seems that you are just reading from local hard drive... Tijnema _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/
Re: [PHP] FW: looking for two remote functions
Tijnema ! wrote: I'm not very familiar with PERL, so will this work with remote files? As it seems that you are just reading from local hard drive... Tijnema It has to be on the machine from which the pages are being served. There have been several workable suggestions for different possibilities. I think it would help if you gave the context for this. Are these pages on your own web site? Are you downloading pages from third-party web sites using the browser? Are you using the command line to download pages from other servers? Here is a script which will get the headers for any file you can download from the web: ?php $fp = fsockopen(www.example.org, 80, $errno, $errstr, 30); if (!$fp) { echo $errstr ($errno)br /\n; } else { $out = HEAD http://www.example.org/any_page.html / HTTP/1.1\r\n; $out .= Host: www.example.org\r\n; $out .= Connection: Close\r\n\r\n; fwrite($fp, $out); $header = ; while (!feof($fp)) { $header .= fgets($fp, 256); } fclose($fp); echo $header; } ? In response you will get the headers: HTTP/1.1 200 OK Date: Sun, 11 Mar 2007 14:57:54 GMT Server: Apache/2.0.51 (Fedora) Last-Modified: Sun, 11 Mar 2007 13:00:03 GMT ETag: 10eb0036-4d1-3c2bbac0 Accept-Ranges: bytes Content-Length: 1233 Connection: close Content-Type: text/plain; charset=UTF-8 This includes the content-length, which is what you want. This script will download only the headers. You will not get a content-length headers for php files, since they are in effect scripts and their length is not know in advance. The same holds true for files which contain SSI. _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FW: looking for two remote functions
On 3/11/07, Myron Turner [EMAIL PROTECTED] wrote: Tijnema ! wrote: I'm not very familiar with PERL, so will this work with remote files? As it seems that you are just reading from local hard drive... Tijnema It has to be on the machine from which the pages are being served. He was looking for remote functions There have been several workable suggestions for different possibilities. I think it would help if you gave the context for this. Are these pages on your own web site? Are you downloading pages from third-party web sites using the browser? Are you using the command line to download pages from other servers? Here is a script which will get the headers for any file you can download from the web: ?php $fp = fsockopen(www.example.org, 80, $errno, $errstr, 30); if (!$fp) { echo $errstr ($errno)br /\n; } else { $out = HEAD http://www.example.org/any_page.html / HTTP/1.1\r\n; $out .= Host: www.example.org\r\n; $out .= Connection: Close\r\n\r\n; fwrite($fp, $out); $header = ; while (!feof($fp)) { $header .= fgets($fp, 256); } fclose($fp); echo $header; } ? In response you will get the headers: HTTP/1.1 200 OK Date: Sun, 11 Mar 2007 14:57:54 GMT Server: Apache/2.0.51 (Fedora) Last-Modified: Sun, 11 Mar 2007 13:00:03 GMT ETag: 10eb0036-4d1-3c2bbac0 Accept-Ranges: bytes Content-Length: 1233 Connection: close Content-Type: text/plain; charset=UTF-8 This includes the content-length, which is what you want. This script will download only the headers. You will not get a content-length headers for php files, since they are in effect scripts and their length is not know in advance. The same holds true for files which contain SSI. This is exactly what my script also did, get the content-length from the header. But i don't see what the actual problem is, there have been a lot of solutions around here but they are all wrong? Tijnema _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FW: looking for two remote functions
I think we've been talking to ourselves. The guy with the original question seems to have folded his hand and gone home. This is exactly what my script also did, get the content-length from the header. But i don't see what the actual problem is, there have been a lot of solutions around here but they are all wrong? Tijnema -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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 írta: Thank you Mickey, but I have already looked in there and the function posted in the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote: Hello everybody, I am looking for an HTTP function for getting remote filesizes. Keeping in mind that I am NOT interested in getting the size on disk figure, I need the actual size of the files when downloaded to a local machine. Please let me know if there are any.. Another thing, I also need a remote function that gets the created date and last modified separately, if possible.. Best regards Try 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.php
RE: [PHP] FW: looking for two remote functions
Actually if right click on any file or folder on a machine you will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk Riyadh -Original Message- From: Németh Zolt?n [mailto:[EMAIL PROTECTED] 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 ?rta: Thank you Mickey, but I have already looked in there and the function posted in the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote: Hello everybody, I am looking for an HTTP function for getting remote filesizes. Keeping in mind that I am NOT interested in getting the size on disk figure, I need the actual size of the files when downloaded to a local machine. Please let me know if there are any.. Another thing, I also need a remote function that gets the created date and last modified separately, if possible.. Best regards Try 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.php
Re: [PHP] FW: looking for two remote functions
On 3/10/07, Németh Zoltán [EMAIL PROTECTED] wrote: 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 will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk okay then what about this? function real_filesize_linux($file) { @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 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:[EMAIL PROTECTED] 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 ?rta: Thank you Mickey, but I have already looked in there and the function posted in the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote: Hello everybody, I am looking for an HTTP function for getting remote filesizes. Keeping in mind that I am NOT interested in getting the size on disk figure, I need the actual size of the files when downloaded to a local machine. Please let me know if there are any.. Another thing, I also need a remote function that gets the created date and last modified separately, if possible.. Best regards Try 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.php
Re: [PHP] FW: looking for two remote functions
Tijnema ! wrote: On 3/10/07, Németh Zoltán [EMAIL PROTECTED] wrote: 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 will see that there are two values (Size on disk Size). Files and folders are stored on the disk in what is called clusters (a group of disk sectors). Size on disk refers to the amount of cluster allocation a file is taking up, compared to file size which is an actual byte count. As I mentioned before what I want is a function for getting the result for the Size no for Size on Disk okay then what about this? function real_filesize_linux($file) { @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 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:[EMAIL PROTECTED] 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 ?rta: Thank you Mickey, but I have already looked in there and the function posted in the notes is working just fine for getting the size on disk which I am not interested in.. Riyadh -Original Message- From: Mikey [mailto:[EMAIL PROTECTED] Sent: 9/Mar/2007 2:57 PM To: php-general@lists.php.net Subject: Re: looking for two remote functions Riyadh S. Alshaeiq wrote: Hello everybody, I am looking for an HTTP function for getting remote filesizes. Keeping in mind that I am NOT interested in getting the size on disk figure, I need the actual size of the files when downloaded to a local machine. Please let me know if there are any.. Another thing, I also need a remote function that gets the created date and last modified separately, if possible.. Best regards Try 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.php This 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). 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: |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/