Jump to content

[SOLVED] large image won't show


contra10

Recommended Posts

I'm not sure why this is happening but the images are saved on the database via a users account. KiB files will show but MiB files do not show.

 

My Max_File_Size does not limit the amount and nowhere in my coding is there a limit to the amount. Plus I can see the actual size and presense of the photo in my database. Any ideas as to why it won't show?

 

PLEASE HELP

Link to comment
Share on other sites

this is the viewing

 

<?php
// Create MySQL login values and 
// set them to your login information.
$username = "";
$password = "";
$host = "localhost";
$database = "userimages";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$connect = mysql_select_db($database) or die("Can not select the database: ".mysql_error());


$id = $_GET['id'];

if(!isset($id) || empty($id)){
die("Please select your image!");
}else{

$query = mysql_query('SELECT `image` FROM `tbl_images` WHERE `userid`= "'.$id.'"');
$row = mysql_fetch_assoc($query);
$content = $row['image'];



$im = imagecreatefromstring($content)or die("Can not select the database: ".mysql_error());; 

$x = imagesx($im); 
$y = imagesy($im); 


$desired_width = 300; 
$desired_height = $y * ($desired_width/$x); 

$new = imagecreatetruecolor($desired_width, $desired_height)or die("Can not select the database: ".mysql_error());; 



imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y)or die("Can not select the database: ".mysql_error());; 

imagedestroy($im); 

header('Content-type: ' . $row['type'] .'');
imagejpeg($new, null, 85);
}
?>

 

 

Link to comment
Share on other sites

How big is the image you are trying to display and what is your Memory limit set at?

 

Reason to ask, it could be eating up more memory than you think. $content takes up as much as it has, then $im now has that as well, so your memory doubled there. Then you resample it, which now your memory has tripled. You do destroy it, but you have used 3 times the memory.

 

So if the image is 3MiB and your Memory limit is set to 8M then there is your answer. It went over the limit. You can try and temporarily increase the limit and see what happens:

 

<?php
// Create MySQL login values and 
// set them to your login information.
$username = "";
$password = "";
$host = "localhost";
$database = "userimages";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$connect = mysql_select_db($database) or die("Can not select the database: ".mysql_error());

$id = $_GET['id'];

if(!isset($id) || empty($id)){
    die("Please select your image!");
}else{
    // Incase my items did not work uncomment the below and try that:
    // ini_set("memory_limit", "32M"); // set the memory limit to 32M to see if that is the issue.

    $query = mysql_query('SELECT `image`, `type` FROM `tbl_images` WHERE `userid`= "'.$id.'"'); // added type here cause you use it later.
    $row = mysql_fetch_assoc($query);

    // $content = $row['image']; // Why do this?
    $im = imagecreatefromstring($row['image']); // or die not needed this is not a sql statement.

    unset($row['image']); // hopefully clear up memory

    $x = imagesx($im); 
    $y = imagesy($im); 

    $desired_width = 300; 
    $desired_height = ($y * ($desired_width/$x)); 

    $new = imagecreatetruecolor($desired_width, $desired_height);  // or die not needed you are not running sql here.
    imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y); // or die not needed you are not running sql here.

    imagedestroy($im); 
    unset($im); // for good measure

    // you never pulled type out of the DB, added that column to the query so this part would work.
    header('Content-type: ' . $row['type'] .'');
    imagejpeg($new, null, 85);
}
?>

 

Some basic items added to increase/improve performance. See what happens.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.