Php 动态图像库
大家好,我的第一篇帖子:D 问题: 我正在尝试制作一个模板库,而不是一个幻灯片,我可以在多个站点上轻松地重用它。Php 动态图像库,php,javascript,image,gallery,Php,Javascript,Image,Gallery,大家好,我的第一篇帖子:D 问题: 我正在尝试制作一个模板库,而不是一个幻灯片,我可以在多个站点上轻松地重用它。 大多数情况下,对于快速对开本网站,其所有者不知道如何更新代码以添加图片 它需要从选定目录中读取所有图像文件。(jpg、gif、png、bmp) 它需要能够在不更改任何代码的情况下更新内容。(从文件夹动态加载) 它需要将img标签写入已查看的页面。(使用JavaScript进行定制/css?) php/JavaScript输出的一组img标记需要是缩略图,单击后将链接到完整的def图片
大多数情况下,对于快速对开本网站,其所有者不知道如何更新代码以添加图片 它需要从选定目录中读取所有图像文件。(jpg、gif、png、bmp) 它需要能够在不更改任何代码的情况下更新内容。(从文件夹动态加载) 它需要将img标签写入已查看的页面。(使用JavaScript进行定制/css?) php/JavaScript输出的一组img标记需要是缩略图,单击后将链接到完整的def图片,这可能可以在最初创建链接时用JavaScript处理 进展: 我发现了一个php脚本,它将从文件夹中读取文件,并将URL保存到数组中,以便在JavaScript中使用。 但是,用于显示图片的代码是作为一个单块幻灯片放映完成的,我需要它分别发布所有图像,而不仅仅是替换同一图像的src 例如: root/index.htm-pastebin[.]com/m52568ed5
root/images/getimages.php-pastebin[.]com/f5395a572
root/images/pic01.png
root/images/pic03.jpg
root/images/asdfs.gif 那么,如何让JavaScript在galleryarray[curimg]中循环并写出我的链接呢 我走了这么远,被卡住了
function rotateimages(){
// document.getElementById("slideshow").setAttribute("src", "res/gallery/painting/"+galleryarray[curimg])
// curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
for (curimg=1;curimg!=0;curimg++;) {
document.write("<div><img class='gallery' src='" + galleryarray[curimg] + "' /></div>")
}
}
函数rotateimages(){
//document.getElementById(“slideshow”).setAttribute(“src”、“res/gallery/painting/”+galleryarray[curimg])
//curimg=(curimg您可以使用PHP写出img标记
此外,for循环将无限运行,因为它有一个始终为真的结束条件
编辑:看看你的粘贴库,你似乎误解了PHP的工作原理。
不起作用,因为脚本标签是在客户端读取的。PHP是在服务器端运行的。要运行res/getimages.PHP
,你必须执行以下操作:
<?php //This is a PHP opening tag; anything after this is PHP code
include('res/getimage.php'); //Imports the PHP file into index.php
?> <!--this is the closing PHP tag - anything after this is HTML -->
我强烈建议您学习一个快速教程,例如,它将真正帮助您完成这一过程。对于,也一样。您可以不断地询问这一切是如何工作的,但您永远不会真正理解它,也无法解决如何将所有的部分放在一起。只需花几个小时!非常简单的自动图库脚本t、 photos.php:
<?php
function getDirTree($dir,$p=true) {
$d = dir($dir);$x=array();
while (false !== ($r = $d->read())) {
if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
$x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
}
}
foreach ($x as $key => $value) {
if (is_dir($dir.$key."/")) {
$x[$key] = getDirTree($dir.$key."/",$p);
}
}
ksort($x);
return $x;
}
$tree = getDirTree("./foto/");
echo '<div id="gallery">';
echo '<ul class="linone">';
foreach($tree as $element => $eval) {
if (is_array($eval)) {
echo '<li><h4>'.$element.'</h4>';
echo '<ul class="linone photos">';
foreach($eval as $file => $value) {
if (strstr($file, "jpg")) {
$file = 'foto/'.$element.'/'.$file;
echo '<li><a href="'.$file.'"><img src="'.$thumb.'" alt="'.$thumb.'"/></a></li>';
}
}
echo '</ul>';
echo '</li>';
}
}
echo '</ul>';
echo '</div>';
感谢所有帮助过他的人,非常感谢谢尔盖·库涅佐夫(Sergey Kunetsov)的画廊脚本,经过轻微修改后,脚本效果非常好
对于任何想要它的人,这里是最后的工作php
显示的文件夹是$path
享受吧,再次感谢。好的,很酷,但我不知道用php来做这件事:)介意帮我吗?是的,我知道它运行不确定,我该如何停止它是我的一个问题。顺便说一句,天哪,这是一个快速的回答。那么你为什么要把这个问题标记为PHP?因为就像skilldrick说的,你可以用PHP编写img标记,我只是不知道怎么做。我的意思是,如果你不懂PHP,为什么要这样标记?PHP解决方案不是这样的看起来很有趣,我会给它一个破解并发布结果。我更改了目录并上传了,但它不起作用:这是我当前加载php的htm文件-你不能包含带有标记的php文件(带有标记,你可以包含JS文件),我向你展示一个index.php文件(没有和其他标记)。好的,你可以按照我在编辑的答案中显示的那样制作,等等。你的代码缺少ed“>”即使如此,我尝试了一下,没有出现任何图片,没有错误,什么都没有。是的,当然。如果你的脚本文件充满了PHP代码,你需要在结尾处写“”(但这不是必需的,但关于这条规则,请了解高级PHP程序员:))。但是,如果您混合编写HTML和PHP代码,则需要使用“”标记启动PHP部件。
<?php //This is a PHP opening tag; anything after this is PHP code
include('res/getimage.php'); //Imports the PHP file into index.php
?> <!--this is the closing PHP tag - anything after this is HTML -->
<?php
function getDirTree($dir,$p=true) {
$d = dir($dir);$x=array();
while (false !== ($r = $d->read())) {
if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
$x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
}
}
foreach ($x as $key => $value) {
if (is_dir($dir.$key."/")) {
$x[$key] = getDirTree($dir.$key."/",$p);
}
}
ksort($x);
return $x;
}
$tree = getDirTree("./foto/");
echo '<div id="gallery">';
echo '<ul class="linone">';
foreach($tree as $element => $eval) {
if (is_array($eval)) {
echo '<li><h4>'.$element.'</h4>';
echo '<ul class="linone photos">';
foreach($eval as $file => $value) {
if (strstr($file, "jpg")) {
$file = 'foto/'.$element.'/'.$file;
echo '<li><a href="'.$file.'"><img src="'.$thumb.'" alt="'.$thumb.'"/></a></li>';
}
}
echo '</ul>';
echo '</li>';
}
}
echo '</ul>';
echo '</div>';
<!DOCTYPE html>
<html>
<head>
<title>My Gallery</title>
</head>
<body>
<?php require_once('photos.php') ?>
</body>
</html>