Jump to content

[SOLVED] Get a Series of Files


Gafaddict

Recommended Posts

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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>";
 }

?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.