PHP filename variables

Mal1

In Runtime
Messages
221
Does anyone know how to make something that assigns a variable in PHP to an actual file.
(i.e - <?php $filename = root directory\subdirectory\$filename || root directory\sub directory2\$filename ?> )
basically i'm trying to make something that takes the entry value from a form and displays all the pictures related to that query (eg search for "car" finds images "car.jpg, carpet.jpg, mycar.jpg, mycarpet.jpg, etc etc" (sub question, can you use asterisks in filenames to remove the need for exact filename query? if so what is the syntax? - would this be right or no,
<?php if ($filename == "*$filesubject*.jpg") { etc..
and how could you go about getting the automatic .jpg file extension added, i presume something like $filesubject = $filesubject.jpg

Once I have done this, how do you make a loop of all the search results, because they're files.. you can't just $filename++ i presume so how is it done?

Any help would be most appreciated. I only thought of the idea this morning so i've only been going on it an hour or so, but thought best to get the idea in now.

P.S. I'm aware I COULD do something like giving each photo an ID number and then doing a huge database style cross-reference/search, but looking for an easier way that hopefully doesnt include MySQL.
 
on a sub-note, I'm getting the error
"Parse error: syntax error, unexpected T_STRING in root\dir\file.php on line 7" which corresponds to the code..
<?php $filename = christmas%20pictures\mal\$filename or christmas%20pictures\emily\$filename; ?>
Why is it taking the value as a text string instead of the filename contained in either of those directories. (im relatively new to php but I can't find any websites that show how to resolve this problem.)
As far as i'm aware quotations aren't used, I have tried many variations of what I can think of, any help would be much appreciated.
Thanks in advance.
 
ok cancel the second post, just need the picture part,
Heres my code as it stands:

my form file being :
<form action="search.php" method ="POST">
Enter required subject: <input type="text" name="filesubject" />
<input type="submit" name="search" />
</form>

and search.php being:

<html>
<body>

<?php echo $_POST["filesubject"];
$filesubject = $_POST["filesubject"];

$filename = 'christmas%20pictures\mal\$filename' or 'christmas%20pictures\emily\$filename';
if ($filename == "*$filesubject*.jpg") ?> {

<table border=0 width="100%">

<tr><td> <a href="$filename" onMouseover="window.status='enlarge image'; return true" onMouseout="window.status=''; return true"><img src="$filename" width=60 height=60 align=left> </td>
<td> <a href="" onMouseover="window.status='enlarge image'; return true" onMouseout="window.status=''; return true"><img src="" width=60 height=60 align=left> </td>
<td> <a href="" onMouseover="window.status='enlarge image'; return true" onMouseout="window.status=''; return true"><img src="" width=60 height=60 align=left> </td>
<td> <a href="" onMouseover="window.status='enlarge image'; return true" onMouseout="window.status=''; return true"><img src="" width=60 height=60 align=left></td></tr>

}
<?php if ($filename != "*$filesubject*.jpg") echo "Sorry that request has not been found. Please try again."

?>


</body>
</html>

The output of which is "FORM_SEARCH_TEXT { } Sorry that request has not been found. Please try again." plus 4 boxed table cells as there should be.

Obviously the image file doesn't show else I wouldnt be asking this question, the rest are blank until I can sort out the looping problem. And the echo $_POST is only there to check the form worked properly.
Help welcome :)
I'll most probably be updating again soon. (apologies to admins for this multiple posting, but it does lend a sort of tutorial to others also.)
 
I've done an alternate solution to that, but please still feel free to have a go at getting the filename variable like that, an interesting challenge to the best of php'ers.
 
Back
Top Bottom