resize and upload image problem
| From: | Ross | Date: | Sat, 16 Jun 2007 07:05:48 +0000 |
| Subject: | resize and upload image problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-257164@lists.php.net to get a copy of this message | ||
Here is my script. The file is not uploading. In my orignal script it is
$_FILES['userfile']['tmp_name'][$i]; that gets uploaded as I have an array
of images and it loops through. It must be something to do with this line
$tmpName = imagecopyresampled($image_resized, $image, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
that breaks it.
---------------------------------------------
$total= count($_FILES['userfile']['name']);
for ($i=0; $i <$total; $i++) {
$fileName = $_FILES['userfile']['name'][$i];
$tmpName = $_FILES['userfile']['tmp_name'][$i];
$fileSize = $_FILES['userfile']['size'][$i];
$fileType = $_FILES['userfile']['type'][$i];
$image = imagecreatefromjpeg($tmpName);
if ($image === false) { exit; }
Get original width and height
echo $width = imagesx($image);
echo $height = imagesy($image);
// New width and height
$new_width = 200;
$new_height = 150;
// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
$tmpName = imagecopyresampled($image_resized, $image, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
$position=$i+1;
$img_url = $_SERVER['DOCUMENT_ROOT']."/images/$customer_id/". basename(
$_FILES['userfile']['name'][$i]);
//$img_url= $target_path . basename( $_FILES['userfile']['name'][$i]);
if(move_uploaded_file($tmpName, $img_url)) {
chmod('images/'.$customer_id, 0777);
chmod($img_url, 0777);
}
}