11-06-2004, 11:09 PM | #1 (permalink) |
Loves my girl in thongs
Location: North of Mexico, South of Canada
|
[PHP] web content variable & extensions
I have a variable code block used for calling content into my tables (I swear one day I'll get around to laying things out only using css). This variable code specifies that the extension called is a .php file. IE, main.php which is text is called into a table on index.php and inherits the css of index.php.
I want to add .jpg to the list of acceptable extensions. The code currently reads: Code:
$ext = ".php"; $id = "".$id."".$ext.""; if (file_exists($id)) { include($id); } else { include("main.php"); } Is the correct syntax: Code:
$ext = ".php",".jpg";
__________________
Seen on an employer evaluation: "The wheel is turning but the hamsters dead" ____________________________ Is arch13 really a porn diety ? find out after the film at 11. -Nanofever |
11-07-2004, 05:49 AM | #2 (permalink) |
Follower of Ner'Zhul
Location: Netherlands
|
No that wouldn't work... you'd have to make the allowed extensions an array and loop through them like this:
Code:
// The allowed extensions $ext = array(".php",".jpg"); // Try every extension foreach($ext as $extension) { // Build the id $id = $id.$extension; // Check if the file actually exists if (file_exists($id)) { // Include the file and make sure we know that it is included include($id); $included=true; } } // If we have included something, // don't include the main.php any more if (!$included) { // Include the default main.php include("main.php"); }
__________________
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents. - Nathaniel Borenstein |
11-08-2004, 09:54 PM | #3 (permalink) |
Loves my girl in thongs
Location: North of Mexico, South of Canada
|
RelaX, that doesn't work. It stil won't include Jpg's.
If I feed it the url www.arch13.com/splash?id=arch13tag2 or the url www.arch13.com/splash?id=arch13tag2.jpg , It will defualt to main.php as the include. I want to make that image file the else include so that's it what is presented at entrance to the site. Giving your code arch13tag2.jpg as the else include file produces the following php error: Code:
Warning: Unexpected character in input: '' (ASCII=28) state=1 in /homepages/6/d93661089/htdocs/arch13tag2.jpg on line 276 Warning: Unexpected character in input: '' (ASCII=2) state=1 in /homepages/6/d93661089/htdocs/arch13tag2.jpg on line 276 Warning: Unexpected character in input: '' (ASCII=7) state=1 in /homepages/6/d93661089/htdocs/arch13tag2.jpg on line 276 Parse error: parse error, unexpected T_STRING in /homepages/6/d93661089/htdocs/arch13tag2.jpg on line 276
__________________
Seen on an employer evaluation: "The wheel is turning but the hamsters dead" ____________________________ Is arch13 really a porn diety ? find out after the film at 11. -Nanofever |
11-08-2004, 11:01 PM | #4 (permalink) |
Crazy
Location: here and there
|
you're having problems with this because php wants to execute included files. it works for including functions or somethign like that, but if you try to include a .jpg file it will either display the jpeg as ascii values or will blow up. if you want to include a file to display a jpeg the file needs to return a jpeg, not a stream of text.
Perhaps if you could explain what you are trying to do a little better it will be easier to help you.
__________________
# chmod 111 /bin/Laden |
11-09-2004, 09:58 PM | #5 (permalink) | |
Loves my girl in thongs
Location: North of Mexico, South of Canada
|
Quote:
In other words, the dynamic area loads the jpg specified by the else { include("arch13tag2.jpg"); } line in the php. When a link is clicked that take the form splash.php?id=main.php then main.php is loaded into the content area replacing the jpg default. This way my text files in php form (ie main.php) are loaded into the content area and can present the desired information to the visitor. I'm trying to understand how I can modify the origional code so that the links load this content and handle the occasional jpg. Further down the road, I'd like to make my dynamic included php files have a split table and would be interested if anyoe knows if the php synatx of ?id=xxx can handle two variables so that different content could possibly be loaded into a split table form. That way the visitor arrives and sees the arch13tag2.jpg at arrival, clicks on links and they are loaded into the content area replacing the arch13tag2.jpg. If the included php that is desired has a table (in this case a split pane of thumbnails on the left and a second content area on the right), then they can click on the thumbnails and they appear in the right content area. My understanding is that that would require that the url have the variable calling the included php file containing the split table with thumbs and child content area and a second variable calling a larger version of a clicked thumb into the child content area. I'm afraid that I'm just getting confusing now.
__________________
Seen on an employer evaluation: "The wheel is turning but the hamsters dead" ____________________________ Is arch13 really a porn diety ? find out after the film at 11. -Nanofever |
|
11-10-2004, 09:52 AM | #6 (permalink) |
Crazy
Location: here and there
|
you are making this WAYYYYY harder than it needs to be.
first of all, you can include as many query string or get variables as you want. just follow the format ?id=xxx&id2=xxx&id3=xxx so what you really could do is simply $id = $_GET['id']; $ext = '.php'; if(strpos($id, $ext)){ include($id); } else{ echo "<img src=\"path/to/mydefautlimage.jpg\">"; //or echo "<img src=\"$id\">"; if you want to pass the name of the jpg dynamically } if you insist on including a php file and have it return a jpg, you would need it to use the gd libraries to build the image and output it.
__________________
# chmod 111 /bin/Laden |
11-10-2004, 04:07 PM | #7 (permalink) |
Junkie
Location: Florida
|
Is there any reason why you can't just pass the extension along as well? If it's only going to be a matter of jpg or php files, I'd do:
Code:
$id = $_REQUEST['id']; if(file_exists($id.".jpg")) { echo "<img src='$id.jpg'>"; } elseif(file_exists($id.".php")) { include($id.".php"); } else { include("main.php"); } |
11-10-2004, 11:47 PM | #8 (permalink) |
Loves my girl in thongs
Location: North of Mexico, South of Canada
|
theFez and irseg, those both worked great.
now if I call a php file that contains a table with a new variable code block, I can call that second variable using the same script in the included file and by changing the line $id = $_GET['id']; to $id = $_GET['id2']; and using the url syntax ?id=main.php&id2=arch13tag which would cause the line if(file_exists($id.".jpg")) { echo "<img src='$id.jpg'>"; to see that arch13tag is a jpg and echo it into the included pages table right? I blended your code to reach a solution. the code reads as follows and works great so far though I haven't tried double variables yet: $id = $_GET['id']; if(file_exists($id.".jpg")) { echo "<img src='$id.jpg'>"; } elseif(file_exists($id.".php")) { include($id.".php"); } else{ echo "<img src=\"path/to/mydefautlimage.jpg\">"; //or echo "<img src=\"$id\">"; if you want to pass the name of the jpg dynamically } Thank you guys for your help!
__________________
Seen on an employer evaluation: "The wheel is turning but the hamsters dead" ____________________________ Is arch13 really a porn diety ? find out after the film at 11. -Nanofever |
Tags |
content, extensions, php, variable, web |
|
|