-1

I want use of filesize in php but if don't work for me. what do i do?

$img = 'http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg';
echo filesize($img);

Error:

filesize(): stat failed for http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
Me hdi
  • 1,832
  • 6
  • 24
  • 35
  • 2
    check this: http://stackoverflow.com/questions/1401131/easiest-way-to-grab-filesize-of-remote-file-in-php – vaso123 May 18 '16 at 09:48
  • `filesize` function only works for local files. To get the size from url, [This](http://stackoverflow.com/questions/4635936/super-fast-getimagesize-in-php) may help. – choz May 18 '16 at 09:49
  • It works. It even reports an error. You can't `filesize` stuff on servers that aren't yours. – Mjh May 18 '16 at 09:49

2 Answers2

2

filesize() works only with your local files. You have two choices:

  1. Download the file and find the filesize
  2. Use the following get_header method:

function:

$file = get_headers("http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg", TRUE);
echo $file['Content-Length'];

Gives: 69322 as of yours

Moreover, you can also retrieve following details from get_headers:

Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Wed, 18 May 2016 09:55:10 GMT
    [Server] => Apache
    [Last-Modified] => Fri, 29 Apr 2016 16:00:34 GMT
    [Accept-Ranges] => bytes
    [Content-Length] => 69322
    [Connection] => close
    [Content-Type] => image/jpeg
)

There is also a Github gist

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
1

May you are looking for this: Easiest way to grab filesize of remote file in PHP?

$img = "http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg";
$head = array_change_key_case(get_headers($img, TRUE));
echo $filesize = $head['content-length']; //69322

OR

echo strlen(file_get_contents($img)); //69322
Community
  • 1
  • 1
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42