PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How do I pass binary (blob) data from mysql to imagejpeg for a file save?

 October 11, 2022     gd, mysql, php     No comments   

Issue

I'm in the process of converting all my images stored in a DB to a file system structure but can't seem to save them to a file. Here is what I'm trying.

....
$SQL = "SELECT thumbnail FROM profile_image WHERE user_id=7";
$r = mysql_query($SQL) or die ("Error");

$image=mysql_result($r,0,"thumbnail");

$destination = SITE_ROOT .'/photos/7/test.jpeg';

imagejpeg($image, $destination);

//header("Content-type: image/jpeg");
//echo ($image);

It's complaining about an invalid resource...what am I missing?


Solution

Try using imagecreatefromstring to create a valid resource.

// ...
if (false !== $im = imagecreatefromstring($image)) {
    imagejpeg($im, SITE_ROOT . '/photos/7/test.jpeg');
    imagedestroy($im);
}


Answered By - Federkun
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing