Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-12-2005, 06:03 AM   #1
Mal
In Runtime
 
Mal's Avatar
 
Join Date: Jan 2005
Posts: 221
Question PHP filename variables

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

Mal is offline   Reply With Quote
Old 03-12-2005, 06:10 AM   #2
Mal
In Runtime
 
Mal's Avatar
 
Join Date: Jan 2005
Posts: 221
Default

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

Mal is offline   Reply With Quote
Old 03-12-2005, 06:40 AM   #3
Mal
In Runtime
 
Mal's Avatar
 
Join Date: Jan 2005
Posts: 221
Default

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.)
Mal is offline   Reply With Quote
Old 03-12-2005, 03:58 PM   #4
Mal
In Runtime
 
Mal's Avatar
 
Join Date: Jan 2005
Posts: 221
Default

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.
Mal is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 05:12 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0