Jump to content

How to use php to output an image to the browser ?


harishkumar09

Recommended Posts

Rendered how?

 

did you mean like how they have a URL like: http://photosite.com/?image=12345

 

or did you mean resizing and resampleing?

 

No resizing and re-sampling. Just like you use echo to send text to the browser , I tried using <img src=""> tags to make image appear in the browser and it didnt work. May be some syntax error I think.How to use <img src=""> in php ?

Link to comment
Share on other sites

<?php
$imageLocation="http://www.phpfreaks.com/images/logo_main.jpg";//should be absolute location of the image.
header("Content-type: image/jpeg");
echo file_get_contents($imageLocation);
?>

 

Thanks Shenoy , it worked.So I actually have 200 links to images I photographed at a recent air show in a text file.So if I want it all displayed , I guess just have to read it all from the text file , store it in an array and use the file_get_contents() function to output it.Am I right ?

Link to comment
Share on other sites

@Harish,

Ya, you can store the URLs in an array and then iterate the array using foreach() function.

But, remember to send the content type headers only once at the starting of the script, else it will generate warnings.

 

Thanks for the information. Can you please point me to a tutorial or thread which deals with outputting images and uses all the commands you mentioned ?

 

Actually I accomplished what I wanted using <img src='"'> using concatenation operators inside a for loop.

Link to comment
Share on other sites

If you look at the phpBB forum , whenever you include multiple images in a single post , it takes time for all the images to appear , as the post gets completed only when all images are displayed on the browser.

 

But if you include only one image per post , the image is immediately loaded and then the next image is loaded and displayed and so on.

 

In other words , we seem to be able to control the order in which images are downloaded and displayed in the phpBB forum by including just one image or multiple images per post.

 

Now, I would like to have the same effect when I read image links from the aforesaid text file and display it on the browser. I want one image to be displayed at a time. I will be displaying 10 images per page but the browser should not go to the next image until the pervious one has been fully displayed.

 

Can you tell me how to do this ?

Link to comment
Share on other sites

php is server side, that means it outputs after reading a file, but then has nothing to do with the file. I'd say what your looking for is AJAX related. (javascript at the very least). there may be a way to do it in php, but I've never crossed on sorry.

Link to comment
Share on other sites

php is server side, that means it outputs after reading a file, but then has nothing to do with the file. I'd say what your looking for is AJAX related. (javascript at the very least). there may be a way to do it in php, but I've never crossed on sorry.

 

 

Oh thanks a lot Jessi , atleast you responded !

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.