Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7832081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:02:06+00:00 2026-06-02T12:02:06+00:00

Here is the code I am using to try and retrieve an image from

  • 0

Here is the code I am using to try and retrieve an image from a database:

<?php
if($id) 
{
    //please change the server name username and password according to your mysql server setting
    $mysql_server="localhost";
    $mysql_username="myuser";
    $mysql_password="mypass";
    $mysql_database="mydb";
    //connect to database using above settings
    @MYSQL_CONNECT("localhost",$mysql_username,$mysql_password);
    @mysql_select_db("mydb");   
    //select the picture using the id
    $query = "select bin_data,filetype from todo where id=$id";
    //execute the query
    $result = @MYSQL_QUERY($query);
    //get the picture data which will be binary
    $data = @MYSQL_RESULT($result,0,"bin_data");
    //get the picture type. It will change according to file extension it may be either gif or jpg
    $type = @MYSQL_RESULT($result,0,"filetype");
    //send the header of the picture we are going to send
    Header( "Content-type: $type");
    //send the binary data
    echo $data;
};


?>

Instead of displaying the requested image, it displays this icon: (not sure what you call it)… https://i.stack.imgur.com/16c5e.png

Here are all the columns in my table: https://i.stack.imgur.com/ravYm.png

I’m pretty positive I’m doing everything right…not sure what’s going on. Help anyone? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:02:07+00:00Added an answer on June 2, 2026 at 12:02 pm

    IMO only constants should be uppercase (tho I gladly did not know they could be upper),

    Anyway Try this:

    <?php
    $file_not_found = '../not_found_image.jpg';
    //Get the id param from GET else null
    $id = (isset($_GET['id']) && is_numeric($_GET['id']))?$_GET['id']:null;
    
    if($id != null) {
        $mysql_server="localhost";
        $mysql_username="myuser";
        $mysql_password="mypass";
        $mysql_database="mydb";
        //Connect to database using above settings
        mysql_connect($mysql_server,$mysql_username,$mysql_password) or die(mysql_error());
        mysql_select_db($mysql_database) or die(mysql_error());
        //Select the picture using the id
        $query = "SELECT `bin_data`, `filetype` FROM todo WHERE id=".(int)mysql_real_escape_string($id)." LIMIT 1";
        //Execute the query
        $result = mysql_query($query);
    
        //Found
        if(mysql_num_rows($result)==1){
            //Get the picture data which will be binary
            $data = mysql_result($result,0,"bin_data");
            //Get the picture type. It will change according to file extension it may be either gif or jpg
            $type = mysql_result($result,0,"filetype");
            //Send the header of the picture we are going to send + cache
            header('Cache-Control: private, max-age='.(60*60*24*365));
            header('Expires: '.gmdate(DATE_RFC1123,time()+60*60*24*365));
            header("Pragma: private");
    
            header('Content-Type: '.$type);
            header('Content-Length: ' . strlen($data));
            //Send the binary data
            echo $data;
    
        }else{
        //Not found
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Type: image/jpeg');
        header('Content-Length: ' . filesize($file_not_found));
        readfile($file_not_found);
        }
    
    }else{
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Type: image/jpeg');
        header('Content-Length: ' . filesize($file_not_found));
        readfile($file_not_found);
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the error code: The app you are using is not responding. Please try
here is my code i am using to fetch mysql result from 4 different
I'm using some code from here to determine when determining when the last finger
I am using this code to retrieve the values I want from XML: IEnumerable<ForewordReview>
I am trying to retrieve some data from a database using jQuery's $.getJSON method
here is a code : using System; using Nemerle.Collections; using Nemerle.Text; //using Nemerle.Utility; using
Here is the my python code using BeautifulSoup. The main issue is with the
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
Here's the code I'm using to make a custom AlertDialog. public void onButtonClicked(View v)
Here's the code I'm using: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.