proctk Posted July 14, 2007 Share Posted July 14, 2007 i have a form that allows users to up load images. the code is set to end and give an error message if the file is bigger then the set peramitor. is there php script that can reduce the image file size when the user try to upload the file Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 14, 2007 Share Posted July 14, 2007 gd imageresample function. Quote Link to comment Share on other sites More sharing options...
proctk Posted July 14, 2007 Author Share Posted July 14, 2007 where would i find info on this Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 14, 2007 Share Posted July 14, 2007 http://uk.php.net/manual/en/function.imagecopyresampled.php Quote Link to comment Share on other sites More sharing options...
proctk Posted July 16, 2007 Author Share Posted July 16, 2007 HI I have been able to get to this point but get the error message as noted below I think that I'm getting closer. I found the code within this script on the php website but I'm getting this message Warning: Division by zero in /mnt/w0400/d11/s01/b02a5c57/www/familyclick.ca/photos/album.php on line 116 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /mnt/w0400/d11/s01/b02a5c57/www/familyclick.ca/photos/album.php on line 125 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /mnt/w0400/d11/s01/b02a5c57/www/familyclick.ca/photos/album.php on line 127 any help is excellent [code=php:0] //Upload Images $path = '../user_images/'; if(isset($_POST['upLoadImages'])){ foreach ($_FILES['file']['tmp_name'] as $i => $val) : if (is_uploaded_file($_FILES['file']['tmp_name'][$i])) { /*if ($_FILES['file']['size'][$i]>$max_file_size) { $msg = "Image Exceeds maximum file size"; header("location: $url?msg=$msg"); exit; }*/ if (($_FILES['file']['type'][$i]=="image/gif") || ($_FILES['file']['type'][$i]=="image/pjpeg") || ($_FILES['file']['type'][$i]=="image/jpeg") || ($_FILES['file']['type'][$i]=="image/png")) { if (file_exists($path . $_FILES['file']['name'][$i])) { $msg .= "The file already exists, change your file name"; header("location: $url?msg=$msg"); exit; }// Load image // The file $filename = $HTTP_POST_FILES['file']['temp'][$i]; // Set a maximum height and width $width = 200; $height = 200; // Content type /*header('Content-type: image/jpeg');*/ // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output echo $image_p; echo $image; $res = copy($HTTP_POST_FILES['file']['tmp_name'][$i], $path.$user_name."-".$HTTP_POST_FILES['file']['name'][$i]); if (!$res) { $msg .= "upload failed!"; header("location: $url?msg=$msg"); exit; } } else { header("location: $url?msg=$msg"); $msg .="Wrong file type, Must be jpeg, gif or png file types"; exit; } $image = $user_name."-".$HTTP_POST_FILES['file']['name'][$i]; //Set Image Size $image_size = $_FILES['file']['size'][$i]; [/code] Quote Link to comment 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.