include '../../snippets/connect.php'; 

$orgid = $_GET['orgid'];

if(!isset($orgid) || empty($orgid)){

     die("Please select your image!");

}else{

$query = mysql_query("SELECT orghomepic FROM org_home_pic WHERE orgid='".$orgid."'");
$row = mysql_fetch_array($query);
$content = $row['orghomepic'];

   if (empty($content)) {
        **$image  = imagecreatefromjpeg('');  

      header('Content-type: image/jpg');
       imagejpeg($image);**

       } else {

       header('Content-type: image/jpg');
       echo $content;
}

}

So this was working previously and upto maybe 1 week ago it was not working, was wondering if anyone had any suggestions at all as to why it isn't/stopped working... or what i could fundamentally change to get the required result...

Which is if the image in teh database exists use it(this bit works fine)... if it doesnt exist display default (the bold bit - Doesnt Work)

Dani AI

Generated

This thread shows the real cause and the right fix: correctly spotted that the image request was triggering an HTTP auth prompt, and confirmed enabling site authentication is what broke the fallback. Core rule: avoid using an HTTP URL for a local fallback image (GD will perform an HTTP request, which is subject to basic auth, hotlink protection and PHP settings like allow_url_fopen).

Quick troubleshooting checklist:

  • Confirm the image URL returns 200 (a 401/403 indicates auth/hotlinking).
  • Check PHP/GD is installed and error logs for warnings.
  • Verify allow_url_fopen if trying remote files (not recommended for same-host files).
  • Ensure headers are sent before any output (no BOM/whitespace).

Safer approach examples — serve the DB blob with a detected MIME type, and fall back to a local file:

/* serve BLOB from DB */
if (!empty($content)) {
    $info = @getimagesizefromstring($content);
    header('Content-Type: ' . ($info['mime'] ?? 'image/jpeg'));
    header('Content-Length: ' . strlen($content));
    echo $content;
    exit;
}
/* local fallback */
$fallback = __DIR__ . '/media/images/nohomepic.jpg';
if (is_readable($fallback)) {
    header('Content-Type: image/jpeg');
    header('Content-Length: ' . filesize($fallback));
    readfile($fallback);
    exit;
}

Best practices: store and use the real MIME type with BLOBs, prefer storing image paths on disk for static fallbacks, avoid deprecated mysql_* functions (use PDO or mysqli with prepared statements), and add appropriate caching headers to reduce load.

Recommended Answers

All 2 Replies

The url is requesting for user and password, if this is not your domain maybe it's a counter measure for hotlinking issues. If it's yours domain then just use server path, for example:

$image  = imagecreatefromjpeg('/var/www/dev/media/images/nohomepic.jpg'); 

And now it is obvious that this stopped working when i added authentications to my site for the development stage, thank you cereal thread solved.. 1 shot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.