Jump to content

change image file size


proctk

Recommended Posts

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.