使用PHP和jQuery生成动态图像库 [英] Dynamic image gallery generation using PHP and jQuery

查看:117
本文介绍了使用PHP和jQuery生成动态图像库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我脑子里有了一个主意,我想创建一个主意,但不是 确定最好的方法.我想提出这个想法并得到一些 在我深入研究之前,以明智的方式解决此问题 错误的方向!

I've got an idea in my head, something I want to create, but am not sure about the best approach. I'd like to pitch the idea and get some opinions on a smart way to go about this before I dive headfirst in the wrong direction!

我有一个摄影网站,其中显示了一个 几个不同的摄影师.它有缩略图和大图像,并且 它们被组织在ul中的li中.

I've got a photography website that displays multiple portfolios for a few different photographers. It's got thumbnails and large images, and they are organized into li in a ul.

想法:

我想登录时只需要一个密码即可将您带到 该页面允许您上载,重命名或删除指定文件中的文件 目录.该目录将通过下拉菜单中的选择定义 菜单.

I'd like to have a login requiring only a password that takes you to a page allowing you to upload, rename, or delete files in a specified directory. The directory would be defined by a selection in a dropdown menu.

上传图片后,我希望将它们调整为大尺寸 图像和一个大拇指,这个大拇指在一个子目录中,并具有文件 顺序命名.

After the images are uploaded I'd like them to be resized into a large image and a thumb, the thumb in a sub-directory, and have the files named sequentially.

图库页面将自动为文件夹中的每个文件夹创建一个图库 指定的目录.每个包含图片和缩略图的文件夹 文件夹.

The gallery page would automatically create one gallery per folder in a specified directory. Each folder containing the images and a thumb folder.

我的想法:

我正在考虑使用PHP或Perl脚本进行图像上传和操作,并且 也许使用那里的脚本进行AJAX文件上传和操作, 但我想尽可能地编写代码.

I'm thinking PHP or Perl script for image upload and manipulation, and maybe using a script out there for AJAX file upload and manipulation, but I'd like to hand code as much as possible.

我想在每个上传会话完成之后,一个PHP脚本 会在图库文件中生成HTML,而不是每次 访问者访问其创建内容的页面,该页面基于 目录.

I imagine after each upload session is finished that a PHP script would generate HTML into the gallery file, rather than each time a visitor access the page having it create the content based on the directory.

我可以就如何最好地解决此问题获得一些建议吗?

  • 哪种语言最适合 每一步? (我想主要使用jQuery,因为这是我的大部分JS)
  • 关于 方法或顺序?
  • 应避免的事情 一起做吗?
  • Which languages are best suited for each step? (I'd like to use mostly jQuery as that is most of my JS)
  • Any suggestions on the methods or sequence?
  • Things to avoid doing all together?

谢谢!

推荐答案

您所需要的就是一个好的文件上传器,基于jquery的图库插件以及php函数"file_put_contents"的一些帮助. 成功上传后,此处的过程是您的脚本应从所需的文件夹生成正确的图像列表. 示例:

all you need is a good file uploader, jquery based gallery plug in and some help of a php function "file_put_contents". the process here is after a successful upload your script should generate a proper ul li list of images from the desired folder. example:

$theGallery ="<ul class='gallery'>";
$dir = "dir_of/images";
$good_ext = array(".jpg",".gif");


if ($handle = opendir($dir)) {
     while (false!== ($file = readdir($handle))) {
     $ext = strrchr($file,".");
          if(in_array($ext,$good_ext))
          {
          //do something with file
          $theGallery .="<li><img src='".$file."'></li>";
          }
    }
closedir($handle);
}
else
{
$theGallery .="<li>Directory does not exist!</li>";
}
$theGallery .= "</ul>";

,然后添加一些html和javascript代码,例如:

and then add some html and javascript code like:

 $(document).ready(function(){
      $('ul.gallery').toGallery();
 });

有些jQuery插件很容易实现.多亏了选择器.

some jquery plug ins are easy to implement just like that. thanks to the selectors.

脚本的最后一部分,是否将动态生成的html代码放入文件中. 因此我们将使用'file_put_contents'或执行相同操作的任何函数.

the final part of the script if to put your dynamically generated html codes to a file. so we gonna use the 'file_put_contents' or any functions that does do the same.

这篇关于使用PHP和jQuery生成动态图像库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆