Getimagesize在主机服务器-Hostinger中不起作用



代码:

$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>';

如果在localhost=>$size[0]中运行ok-在服务器hostinger=>$size[0]中运行NULLPs:allow_url_fopen is ON(检查人:phpinfo();Tks help@

这是因为目录。

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

是HTML包装程序的路径。但是PHP在服务器的物理目录中查找(类似于您的家用电脑上的C:\examplep/htdocs/my_projects/st.quantrimang.com/photos…(在localhost上,两者(通常(是相同的。在实时服务器上,目录的结构更为复杂,因为每个客户都有自己的子目录。在活动服务器上物理目录的路径中,还包括您的帐号(以及其他内容(。简而言之:使用

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

获取域的服务器根目录。然后

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

应该起作用。

顺便说一句:"allow_url_fopen"在这种情况下不相关。

最新更新