Reputation: 3032
I uploaded some files to a folder, and when I use filesize function I get this message:
Message: filesize() [function.filesize]: stat failed for http://www.books.tahasoft.com/216.ppt
the path of file is:
http://www.books.tahasoft.com/216.ppt
and here is my code:
<?
echo filesize("http://www.books.tahasoft.com/216.ppt");
?>
How can I fix this?
Upvotes: 1
Views: 4643
Reputation: 166
for getting the size of your file from filesize() function, you need to add folder path of the file to get the size.
==> False Method: $filePath = "http://www.books.tahasoft.com/216.ppt";
==> True Method: folder path like: $filePath = '/home/www/uploadpath/filename';
So, you get the result by calling the function like:
filesize($filePath);
OR
If you want to get the size from the link, you have to do like this:
strlen(file_get_contents("http://www.books.tahasoft.com/216.ppt"));
Upvotes: 0
Reputation: 137
You can use like this.......
$ch = curl_init('http://www.books.tahasoft.com/216.ppt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
echo $size;
Upvotes: 3
Reputation: 36214
The best you can do, to perform a HTTP HEAD request to the file, and check existence of the Content-Length
header; the only other way would be to download the whole file, and check its length - but in my opinion is not a real option.
Upvotes: 0
Reputation: 160833
You could do this instead.
echo strlen(file_get_contents("http://www.books.tahasoft.com/216.ppt"));
Upvotes: 1
Reputation: 437336
The http://
stream wrapper does not support the stat
family of functions, so you can't do this with filesize
as the documentation warns:
As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to Supported Protocols and Wrappers to determine which wrappers support stat() family of functionality.
If you need the filesize over HTTP without having to download the whole file first, you might be able to get it using curl
; you can see how to do that here. But keep in mind that this is dependent on what headers the remote server decides to send back; there is no guarantee that it will always work.
Upvotes: 1
Reputation: 21856
You cannot get the filesize over the http protocol.
If the file is on the local server, use filesize with a absolute or a relative path in the filesystem.
Upvotes: 6