另一种检查图像 url 是否有效的方法
Another way to check the image url is valid or not
我正在尝试将大量图像导入我的 .csv 文件中的数据库,但在导入之前,我正在尝试使用 [=15] 检查图像的 url 是否有效=] php.
中的函数
当我使用 getimagesize() 函数检查图像的 url 是否有效时,我的导入速度太慢了。
那么有没有其他方法可以检查图像 URL 并快速导入请建议我,在此先感谢
测试远程 url 的最快方法是使用启用了 NOBODY 标志的 CURL,前提是您的服务器支持它。
function remoteFileExists( $url )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL,$url );
curl_setopt( $ch, CURLOPT_NOBODY, 1 );
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$output = ( curl_exec( $ch ) !== false );
curl_close( $ch );
return $output;
}
我正在尝试将大量图像导入我的 .csv 文件中的数据库,但在导入之前,我正在尝试使用 [=15] 检查图像的 url 是否有效=] php.
中的函数当我使用 getimagesize() 函数检查图像的 url 是否有效时,我的导入速度太慢了。 那么有没有其他方法可以检查图像 URL 并快速导入请建议我,在此先感谢
测试远程 url 的最快方法是使用启用了 NOBODY 标志的 CURL,前提是您的服务器支持它。
function remoteFileExists( $url )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL,$url );
curl_setopt( $ch, CURLOPT_NOBODY, 1 );
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$output = ( curl_exec( $ch ) !== false );
curl_close( $ch );
return $output;
}