我有一个角度应用程序,可以显示一些图像.我正在打开prettyPhoto ajax窗口,并将路径名传递给URL.我的脚本可以很好地加载图像,但是,它并没有像传统上的prettyPhoto那样显示图像.
我需要怎么做才能使其表现为正在显示照片?即:具有全屏按钮,将灯箱调整为照片尺寸等.
那有可能吗?
我通过以下方式打开灯箱:
$scope.openLightbox = function()
{
if (typeof $.prettyPhoto.open !== "function")
{
$.fn.prettyPhoto({
social_tools:false,
deeplinking: false,
keyboard_shortcuts: false
});
$.prettyPhoto.open('resources/php/view/lightbox.php?ajax=true&path=' + $base64.encode($scope.currentFile));
return;
}
$.prettyPhoto.open('resources/php/view/lightbox.php?ajax=true&path=' + $base64.encode($scope.currentFile));
}
$scope.currentFile将类似于:data / 39 / my_image_name.jpg
我像这样解析PHP:
$path = base64_decode($_GET['path']);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
$mimeExt = explode('/', $mime);
if ($mimeExt[0] == 'image')
{
echo '';
}
elseif ($mimeExt[0] == 'video')
{
}
finfo_close($finfo);
就像我在上面说的那样,图像显示得很好,我只希望它以标准的prettyPhoto图像行为显示.我了解这可能无法实现.
编辑
因此,事实证明我毕竟不需要AJAX:
$scope.openLightbox = function()
{
if (typeof $.prettyPhoto.open !== "function")
{
$.fn.prettyPhoto({
social_tools:false,
deeplinking: false,
keyboard_shortcuts: false
});
$.prettyPhoto.open('resources/php/view/lightbox.php?path=' + $base64.encode($scope.currentFile));
return;
}
$.prettyPhoto.open('resources/php/view/lightbox.php?path=' + $base64.encode($scope.currentFile));
}
最后是我的php,我直接将图像输出到浏览器,因此prettyPhoto认为它只是加载图像
require("../config.php");
require("../connect.php");
session_start();
if (isset($_SESSION['ds_level']))
{
$path = base64_decode($_GET['path']);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
$mimeExt = explode('/', $mime);
if ($mimeExt[0] == 'image')
{
header('Content-Type: image/' . $mimeExt[1]);
echo file_get_contents($path);
}
elseif ($mimeExt[0] == 'video')
{
//do other stuff to display video
}
finfo_close($finfo);
}
else
{
//-- no access
}
?>
解决方法:
What do I need to do so it behaves like it is displaying a photo? i.e: has the fullscreen button, resizes the lightbox to the photo etc.
Is that even possible?
.directive('prettyp', function(){
return function(scope, element, attrs) {
$("[rel^='prettyPhoto']").prettyPhoto({deeplinking: false, social_tools: false});
}
})
要应用它,请在锚点中指定rel =“ prettyPhoto”,如下所示:
这个怎么运作
该伪指令查找以prettyPhoto开头的rel属性,然后将prettyPhoto魔术应用到该属性.
例
我制作了一个Plunk,可以玩一下:check the Plunk
用您的代码
要在代码中应用指令,您可以替换:
echo '';
与:
echo '';
聊天后编辑
由于图像受.htaccess保护,因此您选择使用图像的base64版本,为什么不呢?
但是,似乎如果您等到用户单击应用程序中的“查看”按钮,在将其传递给prettyPhoto之前,要获取受保护的图像并对其进行编码会花费太长时间:
我建议您在用户单击列表中的图像时,在用户单击查看按钮之前先获取图像.
漫长的过程:
>对PHP服务器进行ajax调用;
>使php应用程序获取图像;
>让php应用程序对图像进行编码;
>让angularjs / javaScript应用程序存储base64字符串
然后可以在后台自动进行预防性的操作.
然后将优化用户体验.
So when the user does click the view button, the base64 version of the image can be passed to prettyPhoto straight away, without any server call: this would produce the same result as displayed in the plunkr I provided, when the button is pressed.
标签:angularjs,ajax,prettyphoto,php
来源: https://codeday.me/bug/20191120/2042783.html