corrupshun Posted April 29, 2010 Share Posted April 29, 2010 I'm using PHP GD and everytime I upload a file I exported from photoshop/fireworks it crashes. (such as banners in .gif formats) The program basically uploads an image, resizes it based on it's height/width ratio, places it in a new location, and inserts the filename into the database to the corrosponding username. This is the info apace gave me. Quote Problem Event Name: APPCRASH Application Name: httpd.exe Application Version: 2.2.11.0 Application Timestamp: 493f5d44 Fault Module Name: ntdll.dll Fault Module Version: 6.1.7600.16385 Fault Module Timestamp: 4a5bdadb Exception Code: c0000005 Exception Offset: 00046b90 OS Version: 6.1.7600.2.0.0.256.1 Locale ID: 1033 Additional Information 1: 0a9e Additional Information 2: 0a9e372d3b4ad19135b953a78882e789 Additional Information 3: 0a9e Additional Information 4: 0a9e372d3b4ad19135b953a78882e789 that may or may not be helpful.. Here's the code. Please note that apache doesn't comepltly crash, it opens a window that says it stopped running, but still runs. The php page then doesn't load. Here's the PHP: <?php function resize() { if(isset($_COOKIE['username'])) { //----------------------------------------------------------------------- //upload an image that is gif||jpg||jpeg||png && is less than 1mb //save to a temporary spot //set max height and width //get height and width of uploaded file //resize the image and save it to a new location //----------------------------------------------------------------------- //set local variables // $username = $_COOKIE['username']; $maxsize = 10*1048576; // // if(isset($_POST['submit']) && $_POST['submit'] == "Upload!") { if($maxsize > $_FILES['upload']['size']) { if(isset($_FILES['upload']['name']) && isset($_FILES['upload']['size'])) { if(isset($_FILES['upload']['type']) && ($_FILES['upload']['type'] == "image/gif") || ($_FILES['upload']['type'] == "image/jpeg") || ($_FILES['upload']['type'] == "image/pjpeg") || ($_FILES['upload']['type'] == "image/png") || ($_FILES['upload']['type'] == "image/x-png")) { if($_FILES['upload']['error'] > 0) { switch($_FILES['upload']['error']) { case 1: echo 'File is too big for the server to handle.'; break; case 2: echo 'File is bigger than the max file size.'; break; case 3: echo 'File was not uploaded fully.'; break; case 4: echo 'No file was even uploaded.'; break; }//switch }//if error else { ///////////////////SQL//////////////////// $con = mysql_connect('localhost','root'); mysql_select_db("Forum",$con); ///////////// $sql = "SELECT MAX(Avatar) FROM Users"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { $max = $row['MAX(Avatar)']; } $max++; ///////////// $sql = "SELECT Avatar FROM Users WHERE Username='$username'"; $query = mysql_query($sql); while($row = mysql_fetch_assoc($query)) { $current = $row['Avatar']; } ////////////////////////////////////////// ////////////////Variables///////////////// $save = "img/avatars/{$max}.gif"; $max_h = '110'; $max_w = '110'; $name = $_FILES['upload']['name']; $type = $_FILES['upload']['type']; $temp = $_FILES['upload']['tmp_name']; $file = "uploads/$name"; $tempname = "uploads/temp.gif"; $currentav = "img/avatars/{$current}.gif"; ////////////////////////////////////////// move_uploaded_file($temp,"$file"); if($type == 'image/jpeg' || 'image/pjpeg') { $image = imagecreatefromjpeg($file); imagegif($image, $tempname); imagedestroy($image); } else if($type == 'image/png' || 'image/x-png') { $image = imagecreatefrompng($file); imagegif($image, $tempname); imagedestroy($image); } else if($type == 'image/gif') { $image = imagecreatefromgif($file); imagegif($image, $tempname); imagedestroy($image); } list($width, $height) = getimagesize($file); if($height > $width) { $ratio = $height/$width; $f_width = $max_w/$ratio; $f_height = $max_h; } else if($width > $height) { $ratio = $width/$height; $f_height = $max_h/$ratio; $f_width = $max_w; } else if($width == $height) { $f_height = $max_h; $f_width = $max_w; } $box = imagecreatetruecolor($f_width, $f_height); $image = imagecreatefromgif($tempname); imagecopyresampled($box, $image, 0, 0, 0, 0, $f_width, $f_height, $width, $height); unlink($tempname); imagegif($box, $save, 100); unlink($file); unlink($currentav); $insert = "UPDATE Users SET Avatar='$max' WHERE Username='$username'"; if(mysql_query($insert)) { echo '<div class="error">Success.</div>'; } }//else }//if upload else { echo '<div class="error">Form was submitted but nothing was uploaded..<br />'; echo "The MIME type of: {$_FILES['upload']['type']} is not currently allowed.</div>"; }//else }//if name and size isset else { echo '<div class="error">Submitted but not uploaded.</div>'; }//else }//if maxsize else { echo '<div class="error">It\'s too big.</div>'; }//else }//if submit is set else { ?> <form enctype="multipart/form-data" action="avatar.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $maxsize; ?>" /> Avatar File: <input type="file" name="upload" class="dupload" /><br /> <input type="submit" name="submit" value="Upload!" class="dsubmit" /> </form> <?php } } else { echo '<div class="error">You cannot upload an avatar while you are not logged in. <br /> Please <a href="login.php">Log-in</a> or <a href="register.php">Register</a>.</div>'; } }//end of function ?> Thank you to whomever reads this. I greatly appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/200231-apache-crashes-when-i-upload-an-image/ Share on other sites More sharing options...
ChemicalBliss Posted April 29, 2010 Share Posted April 29, 2010 Sounds like a problem with with the system imo. Though there will most likely be a specific function to cause this; Remove pieces of code from your script until it doesn't crash - try to isolate the function/code that causes this. -cb- Quote Link to comment https://forums.phpfreaks.com/topic/200231-apache-crashes-when-i-upload-an-image/#findComment-1050769 Share on other sites More sharing options...
teamatomic Posted April 29, 2010 Share Posted April 29, 2010 Go get a RAM checker and run it for an hour or two, its possible you have bad chip. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/200231-apache-crashes-when-i-upload-an-image/#findComment-1050771 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.