开发者

How to retrieve image from server and display using json parsing?

I have created a form which takes in images into a folder. I have only one image per folder and I want to display the image from the specified folder.

Say I've uploaded one picture to folder name uploads. Now I want to retrieve that image from the folder and display it.

H开发者_JAVA百科ow do I do that?


When a file is uploaded with your form, it becomes a file on your server, immediately. The web server puts it in a temporary directory and PHP tells you where it was put through the $_FILES array. You can immediately access this file, you can move it somewhere within your website's documents, and you can immediately print out an <img> tag pointing to where the file was put.

Stop writing "an img tag won't work" as that is exactly how you display the image.

Read the PHP manual page "Handling file uploads": http://php.net/manual/en/features.file-upload.php

The PHP manual should always be the first place you go when you're trying to do something you haven't done before.


<img src="/path/to/the/upload/folder/<?php echo $filename; ?>"/>

or:

echo '<img src="/path/to/the/upload/folder/'.$filename.'"/>";


First you should have the image and path (or user) names in PHP variables. Then use an IMG tag to display them like :

<img src="some_path/uploads/<?php echo $username . '/' . $imagename; ?>">

you can't do it without knowing the name of the image file.


<?php
  header('Content-Type:image/jpeg');
  readfile('path_to_your/image.jpg');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜