Page 1 of 1

Wildcards and temp directory

Posted: Sun Nov 07, 2010 12:44 pm
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

Re: Wildcards and temp directory

Posted: Sun Nov 07, 2010 1:24 pm
by Jonah Bron
Erm, you're saying you want to make sure that you don't write over an existing file?

Re: Wildcards and temp directory

Posted: Sun Nov 07, 2010 4:10 pm
by McInfo
Try glob() or glob://.

Re: Wildcards and temp directory

Posted: Mon Nov 08, 2010 6:58 am
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";
}
?>

Re: Wildcards and temp directory

Posted: Mon Nov 08, 2010 7:04 am
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"