contra10 Posted April 2, 2009 Share Posted April 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/ Share on other sites More sharing options...
contra10 Posted April 2, 2009 Author Share Posted April 2, 2009 heres the upload form Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/#findComment-799525 Share on other sites More sharing options...
premiso Posted April 2, 2009 Share Posted April 2, 2009 So the image uploads...we would not need to see the upload script then. Where is the script that fetches the image and displays it? Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/#findComment-799526 Share on other sites More sharing options...
contra10 Posted April 2, 2009 Author Share Posted April 2, 2009 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/#findComment-799527 Share on other sites More sharing options...
contra10 Posted April 2, 2009 Author Share Posted April 2, 2009 i'm getting the id of the pic etc, i really dun know why its not working Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/#findComment-799537 Share on other sites More sharing options...
premiso Posted April 2, 2009 Share Posted April 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/#findComment-799548 Share on other sites More sharing options...
contra10 Posted April 2, 2009 Author Share Posted April 2, 2009 THANK YOU, YOUR A LIFE SAVER Quote Link to comment https://forums.phpfreaks.com/topic/152246-solved-large-image-wont-show/#findComment-799568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.