简体   繁体   English

使用PHP和jQuery生成动态图像库

[英]Dynamic image gallery generation using PHP and 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! 我想提出这个想法并以明智的方式获得一些意见,然后再朝错误的方向前进!

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 . 它有缩略图和大图片,并将它们组织成liul

The idea: 这个想法:

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. 每个文件夹都包含图像和一个thumb文件夹。

What I'm thinking: 我在想什么:

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或Perl脚本用于图像上载和操作,并且可能在其中使用脚本来进行AJAX文件上载和操作,但是我想尽可能地编写代码。

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. 我想在每次上传会话结束后,PHP脚本都会将HTML生成到图库文件中,而不是每次访问该页面的访客都根据目录创建内容的HTML。

Could I get some advice on how best to approach this? 我可以就如何最好地解决这个问题获得一些建议吗?

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

Thanks in advance! 提前致谢!

all you need is a good file uploader, jquery based gallery plug in and some help of a php function "file_put_contents". 您只需要一个好的文件上传器,基于jquery的图库插件和php函数“ 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>";

and then add some html and javascript code like: 然后添加一些html和javascript代码,例如:

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

some jquery plug ins are easy to implement just like that. 某些jQuery插件很容易实现。 thanks to the selectors. 多亏了选择器。

the final part of the script if to put your dynamically generated html codes to a file. 脚本的最后一部分,是否将动态生成的html代码放入文件中。 so we gonna use the 'file_put_contents' or any functions that does do the same. 因此我们将使用'file_put_contents'或执行相同操作的任何函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM