![]() |
[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"; Is the correct syntax: Code:
$ext = ".php",".jpg"; |
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 |
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 |
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. |
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. :confused: |
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. |
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']; |
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! |
All times are GMT -8. The time now is 03:01 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project