Gafaddict Posted December 19, 2007 Share Posted December 19, 2007 Anybody here know how to solve this problem? I've seen it done before on another PHP powered site, in fact I'd ask the fellow who coded that site but he seems to have vanished off the face of the earth... anyway: I have a series of files in a directory, 491_1.jpg, 491_2.jpg, 491_3.jpg. Now, I'm trying to figure out a way by which if one was to enter "491_1.jpg" into a text box and have that processed, the script would be able to find all three of those images, more if there were additional images following that syntax, in the directory. Now, if it's impossible to detect that set of files by entering "491_1.jpg," is there something else that could be processed in order to find that set of files? Such as "491_*.jpg" or something? I appreciate this... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 19, 2007 Share Posted December 19, 2007 odds are the image numbers are arbitrary and it uses SQL backend to retrieve all relative images that relate to user 491 or group 491 or what ever it is. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 You can count all the the files in a directory. Then do $image =array(); while($x=0;$x <= $count_files;$x++){ if(file_exists("images/491_".$x.".png" $image[1] = "491_".$x; I know this wouldnt work, but you sort of get the idea Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 19, 2007 Share Posted December 19, 2007 You can count all the the files in a directory. Not technically, glob gets you all the files, and I think you can say glob($num."_".*.".jpg"); Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 I see what you mean Cooldude. I am also guessing your way would be the best way of doing this. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 19, 2007 Share Posted December 19, 2007 don't know if it works, but your method could be a issue if someone deletes part of the pattern, I still think sql backing to it makes it a ton easier, and most likely they aren't looking based on a userID or groupID but the username/group name Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 don't know if it works, but your method could be a issue if someone deletes part of the pattern, I still think sql backing to it makes it a ton easier, and most likely they aren't looking based on a userID or groupID but the username/group name Shouldnt they insert all the file names from the directory into the db first, then do the search? Quote Link to comment Share on other sites More sharing options...
trq Posted December 19, 2007 Share Posted December 19, 2007 You'll want to be pretty carefull to validate your users input using this approuch, it could quite easily open some security wholes. <?php if (isset($_POST['submit'])) { $files = glob('images/' . $_POST['search']) { foreach($files as $file) { echo "<img src=\"images/$file\"><br />"; } } else { echo "<form method=\"post\">"; echo " <input type=\"text\" name=\"search\">"; echo " <input type=\"submit\" name=\"submit\">"; echo "</form>"; } ?> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 19, 2007 Share Posted December 19, 2007 Well going with what thorpe said the raw files shouldn't be touched or searched. When a person uploads to your server you want to be able to trace who uploaded what. By using SQL to back it you can not only organize it, add extra info to the images/files, but you can then store it logically and recall it securely and carefully, because you can lockdown access to that directory and then let your server hand files out, like a library hand out books at a library. Think of the images like those "special books" you can only get as per a request. You as the librarian (the server) for books matching a criteria phrase, and it returns you those, instead of you searching through, maybe finding stuff you shouldn't. Moral of the story the customer isn't suppose to come behind the counter hunting for stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.