load a php image using src

前端 未结 6 1264
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 10:46

Is it possible to load a image using:


?

for image.php:

$ima         


        
相关标签:
6条回答
  • 2020-12-20 10:59

    You have to change the header content-type and print the contents of the image file. Here is an example for your image.php file:

    $image_id = $_GET['image_id']; 
    $filename = "image".$image_id.".png"; 
    header('Content-Type: image/png');
    print file_get_contents($filename);
    
    0 讨论(0)
  • 2020-12-20 11:07

    one liner....

    echo (file_exists($_GET['image_id'])) ? header("Content-Type:image/png").readfile($_GET['image_id']).die() : false;
    
    0 讨论(0)
  • 2020-12-20 11:08

    Is it possible to load a image use: <img src="image.php?image_id=1">

    Yes. URLs are URLs. It is content-type that determines content, not any characters in the URL itself.

    $image_id = $_GET['image_id']; echo "image".$image_id.".png";

    Not like that. You either have to read the image file in and then output it with a suitable content-type, or redirect (with a location header) to a static image.

    0 讨论(0)
  • 2020-12-20 11:09

    No, this is not possible that way. You would have to write the contents of the image file to the output stream instead.

    0 讨论(0)
  • 2020-12-20 11:10

    If you have the png contents in the database, follow the other answers. If all you need is the id from the database, simply <img src="image<?=$image_id?>.png">

    0 讨论(0)
  • 2020-12-20 11:13

    you must return a valid image, use file_get_contents or readfile for get the conent of image then output to browser

     header("Content-Type:image/png");
    
        $image_id = $_GET['image_id']; 
    
        if(is_file($file = "image".$image_id.".png") ||  is_file($file = "no_image.png"))
            readfile($file); 
    
    0 讨论(0)
提交回复
热议问题