Getimagesize is not working in host server - Hostinger

195 views Asked by At

Code:

$urli = 'https://st.quantrimang.com/photos/image/2020/02/20/Zalo-bat-tim-quanh-day-1.jpg';
$size = getimagesize($urli);
echo $urli.'.</br>Size:';
echo $size[0].'</br>';

If run in localhost => $size[0] ok - Run in server hostinger => $size[0] NULL Ps: allow_url_fopen is ON (check by: phpinfo(); Tks help@

1

There are 1 answers

1
need2know On

Its because of the directory. The

'https://st.quantrimang.com/photos/image/2020/02/20/Zalo-bat-tim-quanh-day-1.jpg';

is the path for the HTML Wrapper. But PHP looks in the physical directory of the server (similar to your C:/xampp/htdocs/my_projects/st.quantrimang.com/photos ... on your Home-PC) On localhost both are (normally) the same. On live server the structure of the directory is more complex, because every customer has its own sub-directory. In the path to your physical directory on the live server are your accountnumber (and other things) also included. In short words: use

$my_server_directory = $_SERVER['DOCUMENT_ROOT']; // could be a very long path

to get the server-root of your domain. Then

$urli = $my_server_directory.'/my_image_directory/image.jpg';
$size = getimagesize($urli);

should work.

Btw: 'allow_url_fopen' is not relevant in this case.