By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

php coding on how display picture

P: 158
Can anyone help me on how display image...i already upload but cannot view or display the image....please help on it
Mar 5 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 296

Where is the image stored, in a database?
Mar 5 '08 #2

P: 158
stored in the same folder...not in the database
Mar 5 '08 #3

Expert 5K+
P: 6,050
stored in the same folder...not in the database
Are you saving anything, at all, in the database? i.e. image locations and urls?

If not, you should really consider doing this; it will make life much, much easier!
Mar 5 '08 #4

P: 310
I am going to give you a sort of complicated tip on how to do something regarding images, but I must say I do not know if this is really what you need here. Depends on what you are trying to do and where the images are located.

In my case, I was creating images on the fly, so to speak, where my PHP scripts called an external application (in this case Sci-Lab) which created an image from some data, and this image was to be shown on the page.

The difficulty in my case, and perhaps also in yours, is that the image to be displayed was not located in the "document tree" and so was not accessible to the browser directly. Also in my case I had to create the image and then delete it afterwards.

What I did was this: In the PHP script that produces the main html code to be sent out to the requester's browser, I include this img tag, here shown using an echo statement:

echo "<img src=\"image.php\" border=\"0\" >";

The php script image.php then looks something like this:

$file = "/var/www/scilab/image_to_be_shown.gif;
header("Content-type: image/gif");
passthru("cat $file");
// unlink ("$file");

What the above does is this: On your main page, the img tag calls the PHP script image.php as this is specified as the source for the image. The function image.php sends the image file out to the browser using the passthru function. In my case I do not want to keep the image file after it is shown (the image is created by the php code that produces the page), so I uncomment the line with the unlink command.

(I actually do things more complicated, where I create a random string in the page code and send that string as a GET argument in the img tag, i.e. image.php?ds=$randomstring, and use this random string as part of the image file name. This lets multiple users access this page at the same time, each creating their own images).

This method allows you to display an image on your page which is not located in the document tree. If your images are located in the document tree, this way of doing things shouldn't be necessary.

Steve, Denmark
Mar 5 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.