Using PHP to output an image, AND some text [SOLVED]
Posted: Fri Feb 27, 2009 2:49 pm
I'm new to PHP; I've messed with Perl a bit, but most of my background is in C. I've scoured the php.net documentation to death, and tried a million different combinations of things to try to get this to work, with no success.
I have a PHP form that will accept image uploads. For security purposes, it moves the image outside of the WWW root, saves it under a random filename, connects to a MySQL database, stores the filename with a unique record number, and returns that record number. To view the image, I have another PHP form that accepts a record number, looks up that record in the database, reads the image from the filename in that record, and displays it.
That all works fine. I use readfile() to output the contents of the image file to the screen. The problem is, there is a piece of text that also gets stored in the database record when the image is uploaded, and I want to display that along with the image. I've spent hours messing with header() and readfile() and content types and boundaries and output buffers and everything else, and if I try to display the image AND the text, I either get an internal server error or the image is broken. Or I get a huge encoded image string.
Ideally I'd like to have PHP spit out an HTML page with the image in it, but I'd settle for outputting the image and a line of plain text. What can I do?
Thanks
I have a PHP form that will accept image uploads. For security purposes, it moves the image outside of the WWW root, saves it under a random filename, connects to a MySQL database, stores the filename with a unique record number, and returns that record number. To view the image, I have another PHP form that accepts a record number, looks up that record in the database, reads the image from the filename in that record, and displays it.
That all works fine. I use readfile() to output the contents of the image file to the screen. The problem is, there is a piece of text that also gets stored in the database record when the image is uploaded, and I want to display that along with the image. I've spent hours messing with header() and readfile() and content types and boundaries and output buffers and everything else, and if I try to display the image AND the text, I either get an internal server error or the image is broken. Or I get a huge encoded image string.
Ideally I'd like to have PHP spit out an HTML page with the image in it, but I'd settle for outputting the image and a line of plain text. What can I do?
Thanks