Wildcards and temp directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dk4210
Forum Newbie
Posts: 9
Joined: Sat Jul 30, 2005 12:06 pm

Wildcards and temp directory

Post by dk4210 »

Hello Guys,

I have an upload script that uploads temp images to a directory called "temp_photo" and each of the images are named by the session first name.last name plus a random number like this for example - johnsmilh21.jpg or johnsmith45.jpg

First thing that I want to do is look in the temp folder to see if the images exists

Code: Select all

$subn = $_SESSION['fname'] . $_SESSION['lname'] ;

$filename = "temp_photo/$subn*.jpg";

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
Not sure what the wild card for the number is.
What would you use to look in the folder and maybe not only see if it exists but also to grab all the names of the images?

I then want to be able to move those images to a perm directory..

Thanks for your help
Last edited by Benjamin on Sun Nov 07, 2010 4:17 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Wildcards and temp directory

Post by Jonah Bron »

Erm, you're saying you want to make sure that you don't write over an existing file?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Wildcards and temp directory

Post by McInfo »

Try glob() or glob://.
dk4210
Forum Newbie
Posts: 9
Joined: Sat Jul 30, 2005 12:06 pm

Re: Wildcards and temp directory

Post by dk4210 »

Jonah
No I just want to read the contents of the directory and pull out certain files. The files with the session fname and lname plus a random number.



mcinfo thanks for the info on Glob. How would I tell what the path is based on this example?

Code: Select all

<?php
foreach (glob("*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}
?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Wildcards and temp directory

Post by s.dot »

dk4210 wrote:<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
?>
*.txt is the file names you are searching for

In your case, you'd want it to be "temp_photo/$subn*.jpg"
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply