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 7178825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:59:54+00:00 2026-05-28T16:59:54+00:00

I have a table named users and each row (user) has an image. The

  • 0

I have a table named users and each row (user) has an image.

The image is stored as a BLOB in a mysql database using this code:

$filename = $_FILES['image']['tmp_name'];
$size = getimagesize($filename);
$handle = fopen( $filename , "rb" );
$content = fread( $handle , filesize( $filename ) );
fclose( $handle );
unlink($filename);
$image = base64_encode( $content );
//  .... send query to database ....

This worked at first, but as more and more images have to be shown at each page, it gets really loaded, so now I want to create thumbnails, saved in the server’s filesystem, using php GD.

I have the following code but I have no idea what to do in order to read the image from the database so I can create its thumbnail.

$query = "SELECT * FROM users;";
$result = mysql_query( $query );
while( $row = mysql_fetch_array( $result ) ) {
    $uploaded_image = base64_decode( $row['image'] );
    $size = getimagesize($uploaded_image);  <--------------------
    $dimension_x = 73;
    $dimension_y = 73;
    $directory = 'views/images/generated/people/';
    do{
    $filename = random_32();
    $filename = $directory.$filename.'.jpg';    
    } while( file_exists($filename) );
$image = imagecreatefromjpeg( $uploaded_image );
$thumb = imagecreatetruecolor( $dimension_x , $dimension_y );
$size = getimagesize( $uploaded_image );
imagecopyresampled( $thumb , $image , 0 , 0 , 0 , 0 , $dimension_x , $dimension_y , $size['0'], $size['1']);
imagejpeg( $thumb , $filename , 100);
}

I am trying to find what should I put where the arrow is to make the script work.

All it does now is output

Warning: getimagesize(ÿØÿà): failed to open stream: No such file or directory in /var/www/play/ns4/models/create_thumbs_people.php on line 12

For every entry in the database.

—- EDIT —-

Forgot to mention, random_32() is a function that generates a 32 characters long random string so that the images are named.

  • 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-28T16:59:55+00:00Added an answer on May 28, 2026 at 4:59 pm

    And here’s one of the many reasons why storing files in the database is a bad idea…

    getimagesize() works on files, not strings. Since you’ve got the raw image in a string, use [imagecreatefromstring()][1], then the imagesx() and imagesy() functions to get the dimensions:

    while( $row = mysql_fetch_array( $result ) ) {
        $uploaded_image = base64_decode( $row['image'] );
        $image = imagecreatefromstring( $uploaded_image );
        $uploaded_x = imagesx($image); // X dimension
        $uploaded_y = imagesy($image); // Y dimension
        etc....
    

    Note that imagecreatefromstring actually has a bit of smarts and can figure out what type the image is, unlike the quite moronic createfromgif/jpg/png/etc… functions, which only work on those particular file types.
    [1]: https://www.php.net/imagecreatefromstring

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My mysql database has a table with several hundred thousand rows. Each row has
I have a user table 'users' that has fields like: id first_name last_name ...
I have a data table. Each row of the table has a commandButton called
Lets say that I have a table containing users . Each row in that
I have a table that has Edit and Delete links in each row. I
I have a DataGridView binded to this table: [Users] ID Name -- ---- 11
I have a table named Info of this schema: int objectId; int time; int
I have a table of Users, Each USR_ID can have multiple Roles,Views,Brands and Units.
I have databases of users and each has tables. I want to loop through
I have a datatable that has a form in each row for changing the

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.