Timur
Timur

Reputation: 3

Get image size with filesize() php

this is my code

$img=("http://dreamhouse.gocrm.uz/".$image->path);

$size=filesize($img);

I want to know image size but I get like this error "local.ERROR: filesize(): stat failed for ..."

what I should do pls give advise

Upvotes: 0

Views: 1178

Answers (1)

Maxime
Maxime

Reputation: 154

If your file is distant, you must download it first using file_get_contents(...url...) or cURL.

$local_path = '/path/to/temporary/file';
$image_contents = file_get_contents("http://dreamhouse.gocrm.uz/" . $image->path);
file_put_contents($local_path, $image_contents);
$size = filesize($local_path);
unlink($local_path);

You may also calculate size from $image_contents without using a tierce file, with mbstring functions.

Upvotes: 1

Related Questions