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

  • SEARCH
  • Home
  • 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 7563701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:43:48+00:00 2026-05-30T13:43:48+00:00

I have an image file which is stored onto database as a blob (shown

  • 0

I have an image file which is stored onto database as a blob (shown in the code). Once resized to 80*80(thumbnail) I need to store it onto some other database. I have resized and saved it as a file but I couldn’t store the resized image onto database. How can I achieve this?

//resize image and save
include('MyImage.php');
$image = new MyImage();
$image->load($tmpName);
$image->resize(80,80);
$image->save('thumbnail.jpg');


//storing original image onto database
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
 $fileName = $_FILES['userfile']['name'];
 $tmpName  = $_FILES['userfile']['tmp_name'];
 $fileSize = $_FILES['userfile']['size'];
 $fileType = $_FILES['userfile']['type'];

 $fp      = fopen($tmpName, 'r');
 $content = fread($fp, filesize($tmpName));
 $content = addslashes($content);
 fclose($fp);

 if(!get_magic_quotes_gpc())
  {
    $fileName = addslashes($fileName);
  }

 $query = "INSERT INTO image_tbl (name, size, type, content )".
           "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
 mysql_query($query) or die('Error, query failed'); 
} 
  • 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-05-30T13:43:50+00:00Added an answer on May 30, 2026 at 1:43 pm

    The direct question to your answer is

    //This goes after the frist block, after "$image->save('thumbnail.jpg');"
    
    $fileSize=filesize('thumbnail.jpg')
    $fp      = fopen('thumbnail.jpg', 'rb');
    $content = fread($fp, $fileSize);
    $content = addslashes($content);
    fclose($fp);
    
    $query = "INSERT INTO image_tbl (name, size, type, content )".
               "VALUES ('thumbnail.jpg', '$fileSize', 'image/jpeg', '$content')";
    mysql_query($query) or die('Error, query failed'); 
    

    You might recognize some elements of that code 🙂

    But believe me, you do not want this:

    • Storing BLOBs in the DB, that the DB doesn’t understand is a bad idea
    • using strings and addslashes to achieve it, is very close to the worst case possible: You read the image into a string consisting of ca 50% unprintables, backslash it, transport it to the DB, where it is unbackslashed and parsed. Use prepared statements with parameters (if you really want to save the image in the DB)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet which serves an image file which was stored in a
I have some code that loads an image file off the web and puts
I have a image file stored at a remote server (i.e http://example.com/images).The images in
I am trying to load an image file (gif) which is stored locally in
I have an application which has a font stored within a jar file. It
I have code which uses the StreamReader to read HTML from a file, then
I have an image file that has all the character sprites that I will
I have image and txt file of same size say 200 KB. Now i
I have a FAT12 image file and I have to open it and read
I have a custom image file where the first block of data is ASCII

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.