SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    loop througj a directory?

    I'm trying to use thie code to explore a directory
    PHP Code:
    $pathtoImages "../providers/images/".$_GET['id'];
    echo 
    $pathtoImages;
    if (
    $dir opendir$pathtoImages )) {
    echo 
    "Directory Handle: $dir\n";
    echo 
    "Entries:\n";

      
    // loop through it, looking for any/all files:
      
    while (false !== ($filename readdir$dir ))) {
          echo 
    "$filename\n";
          
    closedir$dir );
        }

    On
    http://fixmysite.us/masterasp/admin/...nails.php?id=2
    the directory has 2 images in it
    http://fixmysite.us/masterasp/providers/images/2/

    What is the problem here?

    Thanks...
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2011
    Location
    Kolding, Denmark
    Posts
    108
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Try moving closedir( $dir ); outside while loop.

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thx
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Im trying to use the code to create thumbnails for each image in the directory
    PHP Code:
    $thumbWidth 100;  
    $pathtoThumbs "../providers/images/".$_GET['id']."/thumbs/";  
    $pathtoImages "../providers/images/".$_GET['id']."/";

    if (
    $dir opendir$pathtoImages )) {

      
    // loop through it, looking for any/all image files:
      
    while (false !== ($filename readdir$dir ))) {
        
    //  echo "$filename\n";
      // parse path for the extension
      
    $info pathinfo($pathToImages $filename);
      
    // continue only if this is an image
      
    if (( strtolower($info['extension']) == 'jpg' ) || ( strtolower($info['extension']) == 'png' ) || ( strtolower($info['extension']) == 'gif' ))
      {
          if(
    preg_match('/[.](jpg)$/'$filename)) {
          
    $img imagecreatefromjpeg($pathtoImages $filename);
      } else if (
    preg_match('/[.](gif)$/'$filename)) {
          
    $img imagecreatefromgif($pathtoImages $filename);
      } else if (
    preg_match('/[.](png)$/'$filename)) {
          
    $img imagecreatefrompng($pathtoImages $filename);
      }      echo 
    "Creating thumbnail for {$filename} <br />";

          
    $width imagesx($img);
          
    $height imagesy($img);

          
    // calculate thumbnail size
          
    $new_width $thumbWidth;
          
    $new_height floor$height * ( $thumbWidth $width ) );

          
    // create a new temporary image
          
    $tmp_img imagecreatetruecolor$new_width$new_height );

          
    // copy and resize old image into new image
          
    imagecopyresized$tmp_img$img0000$new_width$new_height$width$height );

          
    // save thumbnail into a file
          
    imagejpeg$tmp_img"{$pathToThumbs}{$filename});
          echo 
    '<img src="' $pathtoThumbs $filename '" alt="image" />';
          echo 
    "\n\r";

        }
      }
          
    closedir$dir );

    But it seems like the image isnt copied, resized and moved, heres the result...
    http://fixmysite.us/masterasp/admin/...nails.php?id=2
    Asyou can see by the source, the image isnt available

    Why isn't that function (imagecopyresized()) working?
    "Oh, and Jenkins--apparently your mother died this morning."

  5. #5
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    What have you done in the way of testing? Functions like imagecopyresized and imagejpg return a boolean success value. You should be testing these returns, and on failure echoing the values of the params passed in. That might give you clues as to why it isn't working. Perform these tests and tell us what you find.

  6. #6
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thank you!
    "Oh, and Jenkins--apparently your mother died this morning."


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
  •