Viewed   242 times

how can I display an image retrieved using file_get_contents in php?

Do i need to modify the headers and just echo it or something?

Thanks!

 Answers

1

Do i need to modify the headers and just echo it or something?

exactly.

Send a header("content-type: image/your_image_type"); and the data afterwards.

Wednesday, October 12, 2022
3

In your url try:

http://user:password@site/ 

(append whatever the rest of the URL for your API should be)

Friday, November 4, 2022
 
matoran
 
5

Fixed it. In case anyone has the same problem:


$url = "http://some-adress/test.php";
$headers = get_headers($url, 1);
$content_length = $headers["Content-Length"];
$content = file_get_contents($url, NULL, NULL, NULL, $content_length);
echo $content;


Saturday, December 3, 2022
2

You need to use the source link of your image.

For example, if laravel expose those static files under http://localhost/public/asset/img, then you need to write in your JSX:

<img src="http://localhost/public/asset/img/test.jpg" alt="test" />
Wednesday, December 21, 2022
 
1

If you want to display an image file on the phone, you can do this:

private ImageView mImageView;
mImageView = (ImageView) findViewById(R.id.imageViewId);
mImageView.setImageBitmap(BitmapFactory.decodeFile("pathToImageFile"));

If you want to display an image from your drawable resources, do this:

private ImageView mImageView;
mImageView = (ImageView) findViewById(R.id.imageViewId);
mImageView.setImageResource(R.drawable.imageFileId);

You'll find the drawable folder(s) in the project res folder. You can put your image files there.

Thursday, September 1, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :