search all the files and directories to create thumbnails in php -


I want to search through files and want to create images from JPG files. The code is:

  $ dir2 = opendir ($ direction2); $ Dir = opendir ($ direction); Function create_fcat ($ direction, $ width, $ direction2, $ dir) {while (wrong! == ($ fn = readdir ($ dir))) {$ n_dir = $ direction '/'. $ Fn; If (is_dir ($ n_dir) & amp; $ fn! = '.' & Amp; $ am!; $ Fn! = '..') {if ($ handle = opendir ($ n_dir)) {create_fcat ($ fn, $ Width, $ direction2, $ handle); }} Otherwise ($ fn! = '.' & Amp; $ fn! = '..') {$ ext = Strokehold (substr ($ fn, strlen ($ fn) -3); If ($ ext == 'jpg') {if ($ img = imagecreatefromjpeg ($ direction. '/'. $ Fn)) {$ width_original = imagesx ($ img); $ Height_original = imagesy ($ img); If ($ width_original & gt; $ height_original) {$ new_width = $ width; $ New_height = Floor ($ height_corein * ($ width / $ width_original)); } And {$ new_height = $ width; $ New_width = Floor ($ width_original * ($ width / $ height_original)); } $ Tmp_img = imagecreatetruecolor ($ new_width, $ new_height); Imagecopyresized ($ tmp_img, $ img, 0, 0, 0, 0, $ new_width, $ new_height, $ width_core, $ height_original); Imagejpeg ($ tmp_img, $ direction2. '/ Large' '$ Fn); } Else {echo & lt; P & gt; File can not be loaded. & Lt; / P & gt; '; }}}} Monkey ($ dir); }  

The problem is: For example we have these files:

  • MAIN
    • image1.jpg
    • FOLDER1
      • image2.jpg
      • Folder 1.1
        • image3.jpg

Files are loaded in image1.jpg and image2.jpg, but image3.jpg is not - it seems that folder is considered as file 1.1 How can I fix this?

  $ path = '/ your / top / level / dir'; $ Objects = new recursiveitter iterator (new recursive directoryitter ($ path), recursiveitter iterator :: SELF_first); Forex Currency ($ Objects $ fileinfo) {if ($ fileinfo-> isFile ()) {echo $ fileinfo- & gt; GetFilename () "\ N"; $ Full path = $ fileinfo-> GetPathname (); // Full Path of Image for Resizing}}  

This will give you all the files in one directory and all the sub-directories, then you can change each image as you wish. I always use imagmagick for myself because I think the results are generally better than the GD, but clearly GD is more commonly installed.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -