SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member jagmeet's Avatar
    Join Date
    Apr 2009
    Location
    India, Bhopal
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Gallery Images Sorting

    Hi Frnds

    I m Using Photo Album ..... when i connect to Server through Php FTP script connection .... in image sorting m getting 1 problem.

    Example:
    1.jpg (Main Images)
    2.jpg
    3.jpg
    th_1.jpg (Thumbnail Main Images)
    th_2.jpg
    th_3.jpg

    Prob: my script also Sorting "Thumbnail Pics" but i want to sort only "Main Image"

    How can i set Files Sorting Filter .... plzz help/give me php Filter Function who filter and Remove "th_1.jpg, th_2.jpg, th_3.jpg" from sorting and show only "1.jpg, 2.jpg, 3.jpg"


    Code:
    $dir = "h t t p:/ /w w w.domain.c o m/anyalbum";
    $filearray = array();
    if ($fil = opendir($dir))
    {
    while (($file = readdir($fil)) !== false)
       {
    //if ($file != "." && $file != "..")
    if (strpos($file, '.jpg',1)||strpos($file, '.gif',1) )
          {
    $filearray[] = $file;
          }
       }

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Change this line:

    PHP Code:
    if (strpos($file'.jpg',1)||strpos($file'.gif',1) ) 
    To this:

    PHP Code:
    if ((strpos($file'.jpg'1) !== false || strpos($file'.gif'1) !== false) && strpos($file'th_') != 0

  3. #3
    SitePoint Member jagmeet's Avatar
    Join Date
    Apr 2009
    Location
    India, Bhopal
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sir ...
    thx for reply ...... m going to try dis code

  4. #4
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan, using your suggestion, $filearray would be just an empty array?

    Should be:

    PHP Code:
    if ((stripos($file".jpg"1) !== false || stripos($file".gif"1) !== false) && (stripos($file"th_") == 0)) {
    // not !=, but ==
    // also swtiched to stripos() in case extensions are JPG and what not. 
    Also something to think about, if the file extension happens to be .JPEG, the above if statement would not catch it.

    PHP Code:
    if (preg_match("/\.(jpg|jpeg|gif?)$/i"$file) && !preg_match("/^th_/i"$file)) { 
    Last edited by notepad_coder; Apr 21, 2009 at 23:25.
    - the lid is off the maple syrup again!

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Is it not equivalent to what you wrote? I just added a check that "th_" does not appear at the 0th position of the file name.

  6. #6
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ran it and i get an empty array using !=, switching to == returned the file data.
    - the lid is off the maple syrup again!

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It should be !== instead of !=, like the other conditions, my typo

    Need to differentiate between false and the 0th position, which both evaluate to false

    Using the string functions should be slightly faster than regex for this if it matters

  8. #8
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True, using strpos() is about 90% faster, but using regex lets you define more extension types without a huge if statement :/
    - the lid is off the maple syrup again!

  9. #9
    SitePoint Member jagmeet's Avatar
    Join Date
    Apr 2009
    Location
    India, Bhopal
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sir
    i try both function but m still getting some problem ...... m chking my code .... if i get more problem ill post here more details

    Sir Plzz arrange My Code with above function provided by u !!

    Code:
    $dir = "images";
    $filearray = array();
    if ($fil = opendir($dir))
    {
    while (($file = readdir($fil)) !== false)
       {
    //if ($file != "." && $file != "..")
    if (strpos($file, '.jpg',1)||strpos($file, '.gif',1) )
          {
    $filearray[] = $file;
          }
       }

    my images link: h##p://jagmeetsingh. com/tutorials/album/images/

  10. #10
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $dir "http://jagmeetsingh.com/tutorials/album/images/";
    $filesarray = array();
    if ((
    $fil = @opendir($dir)) !== false) {
        while ((
    $file readdir($fil)) !== false) {
            if (((
    stripos($file".jpg",1) !== false) || (stripos($file".gif"1) !== false)) && (stripos($file"th_") !== 0)) {
                
    $filearray[] = $file;
            }
        }

    - the lid is off the maple syrup again!

  11. #11
    SitePoint Member jagmeet's Avatar
    Join Date
    Apr 2009
    Location
    India, Bhopal
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx sir to rearrange my code ....
    well m learning php

    if i need more help ill contact u... thx again!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •