Is this possible, and how? I want to get the file size of a file, but I may not have the ftp username/password. I found this little code: http://forums.devshed.com/php-develo...rl-102506.html
But, I don't believe it works.
So, is it possible, and what PHP fuction would I use? (I'll then look it up at php.net)
I'm not familiar with Curl..
You can use "file" which returns the file ocntents in array format.(each line)
After imploding it, you can get the file size.
fileStr = implode("",file($url));
strlen(fileStr) should give appropriate results ..
give it a try..
If the file is on the local filesystem, just use the filesize() function. If a remote file, you could try this function you'll find in the users' notes on that page (assuming your PHP installation has the cURL functions enabled):
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Using a curl or a custom function for this is padding. Content-Length is only sent in response to GET/POST (not HEAD) requests. This means a file download will be iniciated and due to PHP being a single thread language it is not possible to abort that file download midstream. This means the only way to ascertain the size of a remote file is to download it in its entirity. Whether once it is local you use Content-Length or strlen() to determine its size is irrelevant.
If the file is on the local filesystem, just use the filesize() function. If a remote file, you could try this function you'll find in the users' notes on that page (assuming your PHP installation has the cURL functions enabled):
But, how will I know if curl is installed? I have a host, and the php on there is 4.4.2, not the most up to date. However, they are trying to work on a split of PHP 5 and PHP 4.
If I'm not wrong, the term "size of file" should give the number of bytes occupied by the file. strlen will return the length of the file, but not the size of the file.
I have a very very crude way for calculating this..
read the file using file_get_contents or by the method i described above.
Save the string as a tmp local file. then use filesize to get the size of the file.
If I'm not wrong, the term "size of file" should give the number of bytes occupied by the file. strlen will return the length of the file, but not the size of the file.
The number of bytes and the file length is the same.
gr8.. I never knew tat.. thnx for that Bokeh.
but new doubts have cropped up in my mind...
I have chked for normal text. It worked perfectly fine. But failed for files containing characters of a different charset. (I chkd for a local Asian language).
pls find below the details of the file which shows the file size on disk.
-rw-r--r-- 1 pin2 pin 6026 Sep 21 13:01 two.asd
But when i used the following code, i got just 39 as the o/p.
$k = implode("",file("two.php"));
echo strlen($k);
where am I missing?
ps: cudn't chk with file_get_contents (4.1.3)
Why don't you get an up to date version? After all it is free.
haha.. Bokeh became angry
I haven't installed anything on my machine.. there is some "test_area" sort of space in our server and I do all my experiments over there.. I hav to install from end-to-end.. which I have been postponing from a long time.. newayz.. i'll take ur advice seriously ..I'll upgrade my version..
Anyway the concept of downloading a terrabyte of data to find the file size seems scary to me. A terrabyte equates to 58 hours download over a T3 or 70 days over a T1.
Bookmarks