I read the manual that filesize() is able to calculate file size from remote file.
However, when I try to do that with snippet below. I got error PHP Warning: filesize(): stat failed for http://someserver/free_wallpaper/jpg/0000122_480_320.jpg in /tmp/test.php on line 5
Here’s my snippet:
$file = "http://someserver/free_wallpaper/jpg/0000122_480_320.jpg";
echo filesize( $file );
Turns out, I can’t use HTTP for
filesize(). Case close. I’ll use
snippet here as a work-around
solution.
filesizedoesn’t work for HTTP – it depends onstat, which isn’t supported for the HTTP(S) protocol.The PHP man page for filesize says:
Refer to List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality.This doesn’t mean every protocol/wrapper works “out of the box” with
filesize. You could always get around that by doing a full GET of the remote URL and calculating the size of the data you get back, of if you can get a Content-Length header you could try a HEAD request to avoid transferring the file data.