Harley1979 Posted July 2, 2007 Share Posted July 2, 2007 Hello, I've been chipping away at this page for days now, originaly it had been working aprt from the odd issue now and then which I would eventually overcome. I think my code is now correct, but no matter what I do the file is lost when submitting even though when I do print_r($_FILES); it gives me the file information and says there is nothing wrong with file either. I'm puzzled, I've tried emptying the cache in the browser, I've set permissions in php.ini and on the folders storing the images. Any ideas anyone? $path = "../gallery/"; $thumbPath = "../gallery/thumbs/"; $max_size = 3000000; $original = $_FILES['imagefile']['tmp_name']; $size = $_FILES['imagefile']['size']; $type = $_FILES['imagefile']['type']; if(isset($original)){ $imageMsg = "You must choose an image to upload"; } if(is_uploaded_file($original)){ if($size > $max_size){ $imageMsg = "The image is just too feckin big!"; $err = true; } if($type == "image/jpeg" || $type == "image/gif"){ // get last image from db $result = mysql_query("SELECT photo FROM gallery ORDER BY id desc LIMIT 1"); $row = mysql_fetch_row($result); // create image name if(empty($row[0])){$photoName = 0;} $photoName = $row[0] + 1; $newName = $photoName.".jpg"; // begin create thumbnail list($width, $height) = getimagesize($original); // set crop size if($width > $height){ $biggestside = $width; } else { $biggestside = $height; } // crop size will be half that of the largest side $croppercent = .15; $cropwidth = $biggestside*$croppercent; $cropheight = $biggestside*$croppercent; // get top left coordinate $cl = array("x"=>($width-$cropwidth)/2, "y"=>($height-$cropheight)/2); // create thumbnail $thumbsize = 75; $thumb = imagecreatetruecolor($thumbsize, $thumbsize); imagecopyresampled($thumb, $original, 0, 0, $cl['x'], $cl['y'], $thumbsize, $thumbsize, $cropwidth, $cropheight); // save to path and destroy temp files imagejpeg($thumb, $thumbPath.$newName); list($origWidth, $origHeight) = getimagesize($original); // if our image is not the desired dimension, resample to default dimensions if($origWidth < $origHeight && $origWidth > 450){ $newHeight = 530; $newWidth = $origWidth * ($newHeight/$origHeight); $resizedImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($resizedImage, $original, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); } elseif($origWidth > $origHeight && $origHeight > 530){ $newWidth = 550; $newHeight = $origHeight * ($newWidth/$origWidth); $resizedImage = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($resizedImage, $original, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); } // copy image to folder $res = imagejpeg($resizedImage, $path.$newName); if(!$res){ $imageMsg = "Upload failed!"; $err = true; } else { $imageMsg = "Upload successful"; imagedestroy($original); imagedestroy($resizedImage); imagedestroy($thumb); } } else { $imageMsg = "Wrong file type!"; $err = true; } Link to comment https://forums.phpfreaks.com/topic/58062-file-upload-problem/ Share on other sites More sharing options...
Harley1979 Posted July 2, 2007 Author Share Posted July 2, 2007 bump Link to comment https://forums.phpfreaks.com/topic/58062-file-upload-problem/#findComment-288010 Share on other sites More sharing options...
Harley1979 Posted July 2, 2007 Author Share Posted July 2, 2007 would it shed any light on the situation if I said "Resource id#6"? This is what I am getting for $resizedImage when I write it to the screen. I can't really understand it though, isn't this normally an error that you get with arrays? Link to comment https://forums.phpfreaks.com/topic/58062-file-upload-problem/#findComment-288087 Share on other sites More sharing options...
Harley1979 Posted July 2, 2007 Author Share Posted July 2, 2007 bump Link to comment https://forums.phpfreaks.com/topic/58062-file-upload-problem/#findComment-288286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.