Asked  7 Months ago    Answers:  5   Viewed   39 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?




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


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

Wednesday, March 31, 2021
answered 7 Months ago

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, May 29, 2021
answered 5 Months ago

Labeeb is right about why you need to set image using path if your resources are already laying inside the resource folder ,

This kind of path is needed only when your images are stored in SD-Card .

And try the below code to set Bitmap images from a file stored inside a SD-Card .

File imgFile = new  File("/sdcard/Images/test_image.jpg");


    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

    ImageView myImage = (ImageView) findViewById(;



And include this permission in the manifest file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Tuesday, June 1, 2021
answered 5 Months ago

The content option is used with POST and PUT requests. For GET you can just append it as a query string:

file_get_contents(''.$getdata, false, $context);

Furthermore, the method defaults to GET so you don't even need to set options, nor create a stream context. So, for this particular situation, you could simply call file_get_contents with the first parameter if you wish.

Friday, July 23, 2021
answered 3 Months ago

Here's a quick example to get you started. You can see it in action here.

function toggleVisibility(id) {
   var el = document.getElementById(id);

   if ("visible") {
     else {
<label for="chkemployment">Employment</label>
<input type="checkbox" id="chkemployment" onChange="toggleVisibility('imgemployment');" /><br/>

<label for="chkpopulation">Population</label>
<input type="checkbox" id="chkpopulation"  onChange="toggleVisibility('imgpopulation');" />
<hr />

<img id="imgemployment" src=""  style="visibility:hidden"/>
<img id="imgpopulation" src=""  style="visibility:hidden" />
Friday, August 6, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :