PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am developing my first PHP site [url]http://www.forthosewhowait.com/restaurant[/url] and now I want to add a feature to the Customer Management System.
I want to allow a user to add images to the text on the CATERING page. I envision the user typing [img-r]filename.jpg[/img] any where on the page, and then have the server display that specified image at that point on the page. I already have an image upload feature that resizes and stores the images in a folder and records image size and path in a table.
The revelant code is below.
I can hardcode the filename in the $imagename = statement and the picture shows, but I can't seem to get the filename.jpg out of the CATERING page into the PHP code.
The image table contains path,width,height data so that is why it is included, but right now I am streamlining the effort to just getting the filename.jpg off the page and into $imagename variable code.
I think my use of REGUALR EXPRESSIONS is good "\[img-r\](.+)\[/img\]", of course that is just my opinion and I may be wrong.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by gregorious on Thu Aug 24, 2006 9:17 am, edited 3 times in total.
feyd wrote:I'd suggest looking into preg_replace_callback().. and just so you know, your [L] tag allows for XSS (cross-site scripting.)
Thanks for the pointers on code submission, I am new to forums. The PHP code highlighting looks much better... now I am wondering if there is a code editor that looks as good (I am using conTEXT now).
I will look into that "callback" feature and revise my linking ([L]) tag. Thanks again.
I want to allow a user to add images to the text on the CATERING page. I envision the user typing [img-r]filename.jpg[/img] any where on the page, and then have the server display that specified image at that point on the page. I already have an image upload feature that resizes and stores the images in a folder and records image size and path in a table.
Like I said, "my first PHP site" so I am still trying to get my mind wrapped around the logic.
I'd suggest looking into preg_replace_callback()..
thanks for the pointer, but preg_replace_callback() went ZOOOM - over my head! I just got introduced to REGEX and my "neural net" got a serious ping from REGEX.
After thinking about the mechanics in simple terms... I may be using the wrong approach; (if I am not mistaken) the eregi_replace is sniffing out the [img]filename[/img] tag and placing the whole tag into a variable $imagename. But all I really need is the filename; so now I am thinking the script should run something like:
Find the tag (stristr), break the tag apart (explode), use the revelant filename (db select) to return the image path, width, size. This appears reasonable enough.
First instincts are usually best followed; so here is a preg_replace_callback attempt.
This code does NOT create any errors, but it still does not replace the code with the image.
How is my syntax ?
lose the "@", add some var_dump() calls to see what's being passed around.
The code allows for XSS and SQL injection. If no results are found it will output a broken image tag.
Thanks for the watchful eye, these forums are encouraging. I did get help with the solution; I just needed to equate the $contentlist variable with the preg_replace_callback statement.