PHP: Retrieve image from MySQL using PDO

后端 未结 4 1811
误落风尘
误落风尘 2020-12-06 22:38

I am refactoring some old code, including rewriting basic mysql queries to use PDO.

The following works brilliantly in all browsers and for all image types:

4条回答
  •  悲&欢浪女
    2020-12-06 23:07

    My personal approach to Image Blobs is using a php file to serve the image, in combination with a GET argument... It's 100% effective and it doesn't involve file creation... For instance, the file to serve the image from the blob would be:

    image.php:

    prepare("SELECT image FROM image where imageid = ?");
        if ($result->execute(array($_GET['imageid']))) {
            $row=$result->fetch();
            echo $row['pic']; //this prints the image data, transforming the image.php to an image
            }
        } // you can put an "else" here to do something on error...
    ?>
    

    This can be called from you main script... For instance:

    
    
    

提交回复
热议问题