Im having problems getting this to work..

What I need to do is scan a directory, and search for all images that belong to the member.

Here's the basic process:

  1. A member uploads a photo

  2. If accepted, the photo is automatically renamed by appending the member's name as a prefix (for example, if the photo being uploaded is named mypicture.png, the photo will be renamed to USERNAME_mypicture.png)

  3. Then the photo is saved to the appropriate folder

So here's where I'm stuck...for some reason I am unable to scan or display the images.

The code that I currently am using (and not working) is below:

//path to directory to scan
$dir = 'http://fling-finder.com/tmp/cache/user-photos/'; 

// Open directory, and proceed to read its contents  
foreach(glob($dir) as $file)  
{  
    echo "filename: $file : filetype: " . filetype($file) . "<br />";  
}

Can anyone see what I am doing wrong here?

The file and directory permissions are set to 755, if that helps

Thank you!

Recommended Answers

All 5 Replies

Member Avatar for stephen_UK

In my program I use:

`echo "<td><img src='$WM'></a></td>";

where $WM is the folder path of the image+ image name and the following code if it is a clickable thumb to enlarge:

<?php echo "<td><a target='blank' href='$IM'><img src='$CR'></a></td>"; ?>

where the variables are folder paths+image name to the respective images
e.g. $pathWM=("./DigitalArchive/300pxWaterMarked20pc/"); // watermarked image then add the filename to the end.

Sorry, should have clarified that this script is for an image gallery -- it will need to get multiple photos, not just one

Member Avatar for diafol
foreach (glob("$dir/$username" . "_*.*") as $filename) {
    echo "$filename size " . filesize($filename) . "<br />";
}

Note that glob won't work on remote dirctories

This is powerfull scandir(), opendir(), alternative for display images inside a folder (for php > 5.1). This Code will display all images in $dir directory.
Assume you have directory $dir = "views/images"; on host http://example.com which only have models, views, and controllers directory. for displaying images (only .jpg) inside $dir directory write these code:

foreach (glob($dir.'/'.'*.jpg') as $file) { 
    echo '<img src="'.$file.'" alt="'.$files.'" /><br />'; 
} 
Member Avatar for diafol

Polite Notice
Please refrain from resurrecting dead posts, especially if you have nothing new to add.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.