如何读取和验证我的 PHP 服务器上是否存在通过 HTTPS 传输的图像?
How do I read and verify if there are images that are on my PHP server but by HTTPS?
我想在我的服务器上查看我的图像,我有另一个子域来保存图像,但它们是通过 HTTPS 提供的
它只能在本地工作,不能通过 HTTPS 远程工作,因为它总是打印 "exists directory".
$foto = "https://subdomain.example.com/images/" . $var . "/" . $var2. "/flayer";
if (file_exists($foto . ".jpg")) {
echo "HELLO WORL";
}
if (glob($foto . ".*")) {
if (file_exists($foto . ".jpg")) {
$ruta = "https://subdomain.example.com/images/". $var . "/" . $var2 . "/flayer.jpg";
}else{
echo "no exists";
}
}else{
echo "no exists on directory";
}
glob()
是目录服务。如果它是您域的子目录,那么您的文件系统应该存储在同一台服务器上。在您的索引文件夹中,将变量定义或存储到此路径 - 将其视为环境变量。
define('PUBLIC_ROOT', dirname(__FILE__));
您现在可以在您的子域中循环浏览您的目录。它将是一个名为您的子域的文件夹。
foreach(glob(PUBLIC_ROOT . '/subdomain/images/*.jpg', GLOB_BRACE) as $image)
// Do something with each JPEG image
如果出于某种原因,您的子域托管在其他地方 - 很奇怪 - 或者它是一个外部站点,并且您需要 使用 HTTP。发送 cURL
请求。您可以在 header.
中指定任何人
$ch = curl_init('https://sub.example.com/images/foo.jpg');
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec ($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200)
// It didn't exist
curl_close($ch);
您不能跨域(通过 HTTP 协议)使用目录服务(DS 协议)。
Moving on point: If you need a collection of all of the images held on that server, then consider building an API that returns a JSON encoded array of all of the file paths or dynamic URI's on your sub domain, then request it from another domain.
我测试了 2 个选项
function remote_file_exists($url, $ext) {
$ch = curl_init($url . $ext);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
return true;
}
}
和
function remote($url, $ext) {
if (@exif_imagetype($url . $ext)) {
return true;
} else {
return false;
}
}
有效但速度太慢,有什么可以更快的吗?
我想在我的服务器上查看我的图像,我有另一个子域来保存图像,但它们是通过 HTTPS 提供的
它只能在本地工作,不能通过 HTTPS 远程工作,因为它总是打印 "exists directory".
$foto = "https://subdomain.example.com/images/" . $var . "/" . $var2. "/flayer";
if (file_exists($foto . ".jpg")) {
echo "HELLO WORL";
}
if (glob($foto . ".*")) {
if (file_exists($foto . ".jpg")) {
$ruta = "https://subdomain.example.com/images/". $var . "/" . $var2 . "/flayer.jpg";
}else{
echo "no exists";
}
}else{
echo "no exists on directory";
}
glob()
是目录服务。如果它是您域的子目录,那么您的文件系统应该存储在同一台服务器上。在您的索引文件夹中,将变量定义或存储到此路径 - 将其视为环境变量。
define('PUBLIC_ROOT', dirname(__FILE__));
您现在可以在您的子域中循环浏览您的目录。它将是一个名为您的子域的文件夹。
foreach(glob(PUBLIC_ROOT . '/subdomain/images/*.jpg', GLOB_BRACE) as $image)
// Do something with each JPEG image
如果出于某种原因,您的子域托管在其他地方 - 很奇怪 - 或者它是一个外部站点,并且您需要 使用 HTTP。发送 cURL
请求。您可以在 header.
$ch = curl_init('https://sub.example.com/images/foo.jpg');
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec ($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200)
// It didn't exist
curl_close($ch);
您不能跨域(通过 HTTP 协议)使用目录服务(DS 协议)。
Moving on point: If you need a collection of all of the images held on that server, then consider building an API that returns a JSON encoded array of all of the file paths or dynamic URI's on your sub domain, then request it from another domain.
我测试了 2 个选项
function remote_file_exists($url, $ext) {
$ch = curl_init($url . $ext);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
return true;
}
}
和
function remote($url, $ext) {
if (@exif_imagetype($url . $ext)) {
return true;
} else {
return false;
}
}
有效但速度太慢,有什么可以更快的吗?