gpt4 book ai didi

php - 如何使用 PHP 从 Azure Blob 存储检索图像并在网站上显示

转载 作者:行者123 更新时间:2023-12-03 05:38:17 24 4
gpt4 key购买 nike

我有一个 Azure Blob 存储帐户和一个其中包含许多图像的文件夹。我希望将图像显示在网站上。该 blob 的路径是 https://example.blob.core.windows.net/example-media/facebook/下面的第一个文件是 index.php,它下面的文件是 gallery.php

屏幕截图显示了我希望图像如何显示。如果您有任何帮助和/或建议,我将不胜感激。

<?php 

$docRoot = $_SERVER['DOCUMENT_ROOT']; //Set document root
require_once "$docRoot/includes/config.php"; //Get global config file
require_once "$docRoot/includes/checklogin.php";
require_once "$docRoot/includes/gallery.php";

$path = "$docRoot" . "facebook/images";
$uri = 'images';

$page_name = "Facebook Image Gallery"; //Page name variable for use in title tag, etc.

//
// Let's reset the title to include the pagename, if it has one
// Shorthand PHP can be hard to read, this is an if (?), else(:)
//
$page_name != "" ? $site_title = $site_title." | ".$page_name : $site_title = $site_title;

?>

<!DOCTYPE html>
<html lang="en">

<?php
$docRoot = $_SERVER['DOCUMENT_ROOT'];
include "$docRoot/includes/header2.php";
?>
<div class="event-top">
<h1>Facebook Image Gallery</h1>
<p>Grab the list of thumbnail images to scroll, or click the forward/back arrow on the right/left of each image to navigate the gallery. Right-click and "Save Image as" to download.</p>
</div>
<div class="campaign-bottom container-fluid"> <!-- lower piece -->
<div class="fotorama" data-auto="false"></div>
</div>
<div class="clearfix"></div>

<script type="text/javascript">
$(function() {

var $window = $(window),
$body = $('body'),
pixelRatio = window.devicePixelRatio || 1,
width = Math.min(760 * pixelRatio, 1280),
ratio = 1.5,
thumbHeight = 56,
thumbWidth = thumbHeight * ratio;

var data = <?= json_encode(galleryContent($path, $uri)) ?>;

$('.fotorama').fotorama({
data: data,
clicktransition: 'dissolve',
width: '100%',
ratio: ratio,
hash: true,
maxheight: '100%',
nav: 'thumbs',
margin: 2,
shuffle: true,
thumbmargin: 2,
thumbwidth: thumbWidth,
thumbheight: thumbHeight,
allowfullscreen: 'native',
navposition: 'top',
keyboard: {
space: true
},
shadows: false,
fit: 'cover'
});
});
</script>

<?php
$docRoot = $_SERVER['DOCUMENT_ROOT'];
include "$docRoot/includes/footer2.php";
?>
</body>
</html>
<?php

/*function isNullOrWhitespace($str)
{
return ($str === null || (strlen(trim($str)) == 0)) ? TRUE : FALSE;
}*/

function galleryContent($path, $uri, $getFolders = false)
{
$list = [];
$parts = scandir($path);

//Look for extension matches and push
foreach ($parts as $name) {

//Clean up path
$fullPath = realpath($path . DIRECTORY_SEPARATOR . $name);
$isDirectory = is_dir($fullPath);
$match = null;

if (($getFolders == $isDirectory) && ($isDirectory
? ($name[0] != '.')
: (preg_match(GALLERY_REGEX, $name, $match) === 1)))

$list[] = [
'name' => $name,
'path' => $fullPath,
//Convert similar extension to single representation (add double tiff?)
'type' => $isDirectory ? 'directory' : str_replace(['jpeg', 'tiff'], ['jpg', 'tif'], $match[2]),
'img' => $uri . '/' . $name,
//'shortname' => $isDirectory ? $name : $match[1],
/*'video' => (!$isDirectory && is_file(
realpath($path . DIRECTORY_SEPARATOR . $match[1] . '.' . GALLERY_VIDEO_TYPE)
)) ? ($uri . '/' . $match[1] . '.' . GALLERY_VIDEO_TYPE) : null*/
'video' => (!$isDirectory && is_file(
realpath($path . DIRECTORY_SEPARATOR . $match[1] . '.' . 'mp4')
)) ? ($uri . '/' . $match[1] . '.' . 'mp4') : null
];
}

return $list;
}

?>

最佳答案

您可以使用Microsoft Azure Storage PHP Client Libraries访问您的 Azure 存储服务。

您可以使用 SDK 生成 SAS 的 URL你的形象。然后直接把网址输入<img src="the_url_with_SAS_of your_image"> ,这样你的图片就应该能够显示在你的页面上了。

这是 generating a link with SAS 的示例。

<小时/>

如果您不关心安全性,可以将图像 blob 设置为公开。这样就可以不用SAS直接访问了。

关于php - 如何使用 PHP 从 Azure Blob 存储检索图像并在网站上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60715046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com