Thank You...
Code: Select all
<?php
ERROR_REPORTING(E_ALL);
//IMPORTANT VARIABLES!!!
$widthMain=100;
$heightMain=100;
$widthThumb=50;
$heightThumb=50;
$imgDir='../ad_images/';//remember trailing '/' if not blank
if($_POST){
//form was posted
//do other stuff here
//create record and get ad_id
$thisAdId='1234';
if($_FILES){//for uploaded files
//image names in form are newImage[]
foreach($_FILES['newImage']['tmp_name'] AS $imId=>$uploadedImage){
if($_FILES['newImage']['size'][$imId]!=''){//make sure that an image was uploaded
$fileName=$imgDir.$_FILES['newImage']['name'][$imId]; //get original name of uploaded image
move_uploaded_file($uploadedImage,$fileName);//copy upload from tmp dir to current dir so we can work with it
list($width, $height) = getimagesize($fileName); //get image dimensions
$imgPathMain=$imgDir.$thisAdId.'_'.$imId.'.jpg'; //main pic name
$imgPathThumb=$imgDir.$thisAdId.'_'.$imId.'_t.jpg'; //thumbnail name
//main image
$imageMain=imagecreatetruecolor($widthMain, $heightMain); //create new image resource
$image=imagecreatefromjpeg($fileName); //get uploaded image data
imagecopyresampled($imageMain, $image, 0, 0, 0, 0, $widthMain, $heightMain, $width, $height);//copy upload to new main pic
imagejpeg($imageMain, $imgPathMain, 100); //create main image
//thumbnail
$imageThumb=imagecreatetruecolor($widthThumb, $heightThumb); //create new image resource
imagecopyresampled($imageThumb, $image, 0, 0, 0, 0, $widthThumb, $heightThumb, $width, $height);//copy upload to new thumbnail pic
imagejpeg($imageThumb, $imgPathThumb, 100); //create main image
unlink($fileName);//delete original upload because we don't need it any more
}
}
}
}
//my example image upload form
echo '<hr><form action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">';
for($i=0;$i<=6;$i++){
echo '<input type="file" name="newImage[]"><br>';
}
echo '<input type="submit" value="Upload Images"></form>';
print_r($_FILES);
?>