I have the following script in order to create a thumbnail, works fine! BUT, when I upload a PNG file with transparent background, for some reason the background change to black.
How to fix? What do I have to do?
This is my Code
<?php
function cwUpload($field_name = '', $target_folder = '', $file_name = '', $thumb = FALSE, $thumb_folder = '', $thumb_width = '', $thumb_height = ''){
//folder path setup
$target_path = $target_folder;
$thumb_path = $thumb_folder;
//file name setup
$filename_err = explode(".",$_FILES[$field_name]['name']);
$filename_err_count = count($filename_err);
$file_ext = $filename_err[$filename_err_count-1];
if($file_name != ''){
$fileName = $file_name.'.'.$file_ext;
}else{
$fileName = $_FILES[$field_name]['name'];
}
//upload image path
$upload_image = $target_path.basename($fileName);
//upload image
if(move_uploaded_file($_FILES[$field_name]['tmp_name'],$upload_image))
{
//thumbnail creation
if($thumb == TRUE)
{
$thumbnail = $thumb_path.$fileName;
list($width,$height) = getimagesize($upload_image);
$thumb_create = imagecreatetruecolor($thumb_width,$thumb_height);
switch($file_ext){
case 'jpg':
$source = imagecreatefromjpeg($upload_image);
break;
case 'jpeg':
$source = imagecreatefromjpeg($upload_image);
break;
case 'png':
$source = imagecreatefrompng($upload_image);
break;
case 'gif':
$source = imagecreatefromgif($upload_image);
break;
default:
$source = imagecreatefromjpeg($upload_image);
}
imagecopyresized($thumb_create,$source,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
switch($file_ext){
case 'jpg' || 'jpeg':
imagejpeg($thumb_create,$thumbnail,100);
break;
case 'png':
imagepng($thumb_create,$thumbnail,100);
break;
case 'gif':
imagegif($thumb_create,$thumbnail,100);
break;
default:
imagejpeg($thumb_create,$thumbnail,100);
}
}
return $fileName;
}
else
{
return false;
}
}
if(!empty($_FILES['image']['name'])){
//call thumbnail creation function and store thumbnail name
$upload_img = cwUpload('image','uploads/','',TRUE,'uploads/thumbs/','200','160');
//full path of the thumbnail image
$thumb_src = 'uploads/thumbs/'.$upload_img;
//set success and error messages
$message = $upload_img?"<span style='color:#008000;'>Image thumbnail have been created successfully.</span>":"<span style='color:#F00000;'>Some error occurred, please try again.</span>";
}else{
//if form is not submitted, below variable should be blank
$thumb_src = '';
$message = '';
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit" name="submit" value="Upload"/>
</form>
<?php if($thumb_src != ''){ ?>
<img src="<?php echo $thumb_src; ?>" alt="">
<?php } ?>
In above code working in JPG and other extension but when i upload transparent image background is getting black
What i am doing wrong ?
Help me
Thanks in advance.
Try this code for PNG
<?php
function cwUpload($field_name = '', $target_folder = '', $file_name = '', $thumb = FALSE, $thumb_folder = '', $thumb_width = '', $thumb_height = ''){
//folder path setup
$target_path = $target_folder;
$thumb_path = $thumb_folder;
//file name setup
$filename_err = explode(".",$_FILES[$field_name]['name']);
$filename_err_count = count($filename_err);
$file_ext = $filename_err[$filename_err_count-1];
if($file_name != ''){
$fileName = $file_name.'.'.$file_ext;
}else{
$fileName = $_FILES[$field_name]['name'];
}
//upload image path
$upload_image = $target_path.basename($fileName);
//upload image
if(move_uploaded_file($_FILES[$field_name]['tmp_name'],$upload_image))
{
//thumbnail creation
if($thumb == TRUE)
{
$thumbnail = $thumb_path.$fileName;
list($width,$height) = getimagesize($upload_image);
$thumb_create = imagecreatetruecolor($thumb_width,$thumb_height);
imagealphablending($thumb_create, false);
imagesavealpha($thumb_create, true);
$trans_layer_overlay = imagecolorallocatealpha($thumb_create, 220, 220, 220, 127);
imagefill($thumb_create, 0, 0, $trans_layer_overlay);
switch($file_ext){
case 'png':
$source = imagecreatefrompng($upload_image);
break;
}
imagecopyresized($thumb_create,$source,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
switch($file_ext){
case 'png':
imagepng($thumb_create,$thumbnail);
break;
}
}
return $fileName;
}
else
{
return false;
}
}
if(!empty($_FILES['image']['name'])){
//call thumbnail creation function and store thumbnail name
$upload_img = cwUpload('image','uploads/','',TRUE,'uploads/thumbs/','200','160');
//full path of the thumbnail image
$thumb_src = 'uploads/thumbs/'.$upload_img;
//set success and error messages
$message = $upload_img?"<span style='color:#008000;'>Image thumbnail have been created successfully.</span>":"<span style='color:#F00000;'>Some error occurred, please try again.</span>";
}else{
//if form is not submitted, below variable should be blank
$thumb_src = '';
$message = '';
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit" name="submit" value="Upload"/>
</form>
<?php if($thumb_src != ''){ ?>
<img src="<?php echo $thumb_src; ?>" alt="">
<?php } ?>
It will work when you upload transparent image.
Related
I want to resize the image file after upload with the help of imagecreatefromjpeg function but this function is unable to access the file from the folder as it's throwing the error i.e., **
imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable
error: in D:\xampp\htdocs\resize\index.php
** but file is uploaded & I wrote the following code.
<form method="post" enctype="multipart/form-data">
<input type="file" name="f1">
<input type="submit" name="btn" value="Upload">
</form>
<?php
ini_set("memory_limit","256M");
if(isset($_POST['btn']))
{
if(move_uploaded_file($_FILES['f1']['tmp_name'], "images/".$_FILES['f1']['name']))
{
$filename = "images/".$_FILES['f1']['name'];
$original_info = getimagesize($filename);
$original_w = $original_info[0];
$original_h = $original_info[1];
echo "<img src =$filename>";
if( ini_get('allow_url_fopen') ) {
// it's enabled, so do something
$original_img = imagecreatefromjpeg($filename);
$thumb_w = 100;
$thumb_h = 60;
$thumb_img = imagecreatetruecolor($thumb_w, $thumb_h);
$thumb_filename = "new.jpg";
imagecopyresampled($thumb_img, $original_img,
0, 0,
0, 0,
$thumb_w, $thumb_h,
$original_w, $original_h);
imagejpeg($thumb_img, $thumb_filename);
imagedestroy($thumb_img);
imagedestroy($original_img);
}
}
}
?>
You must make sure of the type of file.
<?php
$type = exif_imagetype($filename);
// types 1=>gif, 2=>jpg, 3=>png, 6=>bmp
switch ($type) {
case 1 : $img = imageCreateFromGif ( $src );break;
case 2 : $img = imageCreateFromJpeg( $src );break;
case 3 : $img = imageCreateFromPng ( $src );break;
case 6 : $img = imageCreateFromBmp ( $src );break;
}
// or if you cannot use exif_imagetype
// you can use getImageSize
$type = getImageSize($filename);
switch ($type) {
case 'image/gif' : $img = imageCreateFromGif ( $filename ); break;
case 'image/jpeg' : $img = imageCreateFromJpeg( $filename ); break;
case 'image/png' : $img = imageCreateFromPng ( $filename ); break;
case 'image/bmp' : $img = imageCreateFromBmp ( $filename ); break;
}
//// than you can create new file with resize or crop...
?>
I created a function to upload a cropped image from an html5 canvas which works fine. The only issue I have is that the imageinterlace function doesn't create
a progressive jpeg.
if (is_uploaded_file($_FILES['image_file']['tmp_name'])) {
$tmp_name = $folder . $new_name;
move_uploaded_file($_FILES['image_file']['tmp_name'], $tmp_name);
if (file_exists($tmp_name) && filesize($tmp_name) > 0) {
$size = getimagesize($tmp_name);
switch($size[2]) {
case IMAGETYPE_JPEG:
$ext = '.jpg';
$v_image = #imagecreatefromjpeg($tmp_name);
break;
default:
return false;
}
imageinterlace($v_image, 1);
$destination_image = #imagecreatetruecolor( $request['width'], $request['height'] );
imagecopyresampled($destination_image, $v_image, 0, 0, (int)$request['x1'], (int)$request['y1'], (int)$request['width'], (int)$request['height'], (int)$request['w'], (int)$request['h']);
$result_name = $tmp_name . $ext;
imagejpeg($destination_image, $result_name, 90);
}
}
What am I doing wrong?
I'm really new to joomla, I don't have idea what should I do to make it done. I just have this kind of code in administrator table, it refers to uploading files.
//Support for file field: cover
if(isset($_FILES['jform']['name']['cover'])):
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.file');
$file = $_FILES['jform'];
//Check if the server found any error.
$fileError = $file['error']['cover'];
$message = '';
if($fileError > 0 && $fileError != 4) {
switch ($fileError) :
case 1:
$message = JText::_( 'File size exceeds allowed by the server');
break;
case 2:
$message = JText::_( 'File size exceeds allowed by the html form');
break;
case 3:
$message = JText::_( 'Partial upload error');
break;
endswitch;
if($message != '') :
JError::raiseWarning(500,$message);
return false;
endif;
}
else if($fileError == 4){
if(isset($array['cover_hidden'])):;
$array['cover'] = $array['cover_hidden'];
endif;
}
else{
//Check for filesize
$fileSize = $file['size']['cover'];
if($fileSize > 10485760):
JError::raiseWarning(500, 'File bigger than 10MB' );
return false;
endif;
//Replace any special characters in the filename
$filename = explode('.',$file['name']['cover']);
$filename[0] = preg_replace("/[^A-Za-z0-9]/i", "-", $filename[0]);
//Add Timestamp MD5 to avoid overwriting
$filename = md5(time()) . '-' . implode('.',$filename);
$uploadPath = JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_comic'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.$filename;
$fileTemp = $file['tmp_name']['cover'];
if(!JFile::exists($uploadPath)):
if (!JFile::upload($fileTemp, $uploadPath)):
JError::raiseWarning(500,'Error moving file');
return false;
endif;
endif;
$array['cover'] = $filename;
}
endif;
I could upload the file (in this case, an image) from the codes above, but what I'll do next is creating a thumbnail for the uploaded image. I searched for the php codes through the internet but it doesn't seem to work since I can't synchronize it into joomla codes. Umm.. I've made a folder named thumbnail in images folder. So what should I do next?
I'll be so happy and grateful if any of you could help me with this. Thanks.
Well i can share technique I'm using, i hope it will help:
In table's method check after the all validation is done (at the end of the method, just before returning true) i add the following code:
$input = JFactory::getApplication()->input;
$files = $input->files->get('jform');
if (!is_null($files) && isset($files['image']))
$this->image = $this->storeImage($files['image']);
The i create a new method called storeImage() :
protected $_thumb = array('max_w' => 200, 'max_h' => 200);
private function storeImage($file) {
jimport('joomla.filesystem.file');
$filename = JFile::makeSafe($file['name']);
$imageSrc = $file['tmp_name'];
$extension = strtolower(JFile::getExt($filename));
// You can add custom images path here
$imagesPath = JPATH_ROOT . '/media/';
if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
// Generate random filename
$noExt = rand(1000, 9999) . time() . rand(1000, 9999);
$newFilename = $noExt . '.' . $extension;
$imageDest = $imagesPath . $newFilename;
if (JFile::upload($imageSrc, $imageDest)) {
// Get image size
list($w, $h, $type) = GetImageSize($imageDest);
switch ($extension) {
case 'jpg':
case 'jpeg':
$srcRes = imagecreatefromjpeg($imageDest);
break;
case 'png':
$srcRes = imagecreatefrompng($imageDest);
break;
case 'gif':
$srcRes = imagecreatefromgif($imageDest);
break;
}
// Calculating thumb size
if($w > $h) {
$width_ratio = $this->_thumb['max_w'] / $w;
$new_width = $this->_thumb['max_w'];
$new_height = $h * $width_ratio;
} else {
$height_ratio = $this->_thumb['max_w'] / $h;
$new_width = $w * $height_ratio;
$new_height = $this->_thumb['max_w'];
}
$destRes = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($destRes, $srcRes, 0, 0, 0, 0, $new_width, $new_height, $w, $h);
// Creating resized thumbnail
switch ($extension) {
case 'jpg':
case 'jpeg':
imagejpeg($destRes, $imagesPath . 'thumb_' . $newFilename, 100);
break;
case 'png':
imagepng($destRes, $imagesPath . 'thumb_' . $newFilename, 1);
break;
case 'gif':
imagegif($destRes, $imagesPath . 'thumb_' . $newFilename, 100);
break;
}
imagedestroy($destRes);
// Delete old image if it was set before
if (($this->image != "") && JFile::exists($imagesPath . $this->image)) {
JFile::delete($imagesPath . $this->image);
JFile::delete($imagesPath . 'thumb_' . $this->image);
}
return $newFilename;
}
}
}
}
return null;
}
This method returns uploaded file filename, which table stores in 'image' column. It creates two files, one original image and resized thumb with file prefix '_thumb'.
I hope it helps :)
I used Jimage : https://api.joomla.org/cms-3/classes/JImage.html
$JImage = new JImage($img_path);
$size_thumb = '150x150';
$JImage->createThumbs($size_thumb,1,$path.'/thumb');
Short, simple and efficient.
I need to submit form to databse,my form and its php code for submission into database working correctlyn in localserver,but when i upload it in main server after submission an empty php file is shown,no error messages ,data also not entered into database,
when i include the php code for uploaded image this problem arises else other details in form getting submitted successfully.....
As a learner all kind of suggestion is appreciable....Thanks in advance
<?php
error_reporting(E_ALL);
$name = $_POST['name'];
$date = $_POST['year']."-". $_POST['month']."-".$_POST['date'];
$date = mysql_real_escape_string($date);
if (isset($_POST['gender'])){
$gender = $_POST['gender'];
}
if (isset($_POST['maritalstatus'])){
$maritalstatus = $_POST['maritalstatus'];
}
$registerby =$_POST['registerby'];
$livingplace =$_POST['livingplace'];
$qualification =$_POST['quali'];
$occupation =$_POST['occupation'];
$income = $_POST['income'];
$contactno =$_POST['mobno'];
$caste =$_POST['caste'];
$email =$_POST['email'];
if(isset($_POST['submit']))
{
//Assign the paths needed to variables for use in the script
$filePathFull = "/public_html/www.****.com/icons/".$_FILES["imagefile"] ["name"];
$filePathThumb = "/public_html/www.*****.com/icons/";
//Assign the files TMP name and TYPE to variable for use in the script
$tmpName = $_FILES["imagefile"]["tmp_name"];
$imageType = $_FILES["imagefile"]["type"];
//Use a switch statement to check the extension of the file type. If file type is not valid echo an error
switch ($imageType) {
case $imageType == "image/gif":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/jpeg":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/pjpeg":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/png":
move_uploaded_file($tmpName,$filePathFull);
break;
case $imageType == "image/x-png":
move_uploaded_file($tmpName,$filePathFull);
break;
default:
echo 'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.';
}
// Get information about the image
list($srcWidth, $srcHeight, $type, $attr) = getimagesize($filePathFull);
$origRatio = $srcWidth/$srcHeight;
//Create the correct file type based on imagetype
switch($type) {
case IMAGETYPE_JPEG:
$startImage = imagecreatefromjpeg($filePathFull);
break;
case IMAGETYPE_PNG:
$startImage = imagecreatefrompng($filePathFull);
break;
case IMAGETYPE_GIF:
$startImage = imagecreatefromgif($filePathFull);
break;
default:
return false;
}
//Get the image to create thumbnail from
$startImage;
$width = 150;
$height = 150;
if ($width/$height > $origRatio) {
$width = $height*$origRatio;
}else{
$height = $width/$origRatio;
}
//Create the thumbnail with true colours
$thumbImage = imagecreatetruecolor($width, $height);
//Generate the resized image image
imagecopyresampled($thumbImage, $startImage, 0,0,0,0, $width, $height, $srcWidth, $srcHeight);
//Generate a random number to append the filename.
$ran = "thumb_".rand () ;
$thumb2 = $ran.".jpg";
//global $thumb_Add_thumb;
//Create the path to store the thumbnail in.
$thumb_Add_thumb = $filePathThumb;
$thumb_Add_thumb .= $thumb2;
//Create the new image and put it into the thumbnails folder.
imagejpeg($thumbImage, "" .$filePathThumb. "$thumb2");
}
if(isset($_POST['submit']))
{
$connection = mysql_connect("localhost","user", "pass");
if(! $connection) { die('Connection Failed: ' . mysql_error()) ;}
mysql_select_db("database") or die (error.mysql_error());
$sql = "INSERT INTO quickregister(Name,Gender,Dateofbirth,Maritalstatus,Qualification,Income,Livingplace,Caste,Contactno,Emailaddress,Registerby,picture,filePathThumb,Occupation)VALUES('".$name."','".$gender."','".$date."','".$maritalstatus."','".$qualification."','".$income."','".$livingplace."','".$caste."','".$contactno."','".$email."','".$registerby."','".$filePathFull."','".$thumb_Add_thumb."','".$occupation."')";
$retval = mysql_query( $sql, $connection );
if(! $retval )
{
die('Could not enter data' . mysql_error());
}
echo "<b>Your data was added to database</b>";
}
?>
You switch code makes no sense. Apparently you missed the point of switch/case vs. if and this is wrong:
switch ($imageType) {
case $imageType == "image/gif":
move_uploaded_file($tmpName,$filePathFull);
break;
...
default:
echo 'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.';
}
and should be:
switch ($imageType) {
case "image/gif":
move_uploaded_file($tmpName,$filePathFull);
break;
I need to know if is possible have in one form 4 fileupload, each one to save in different folder when a user want affiliate to our service.. like per example in first upload the Curriculum, next the photo and for the last two the diploma's..
Here is the form URL I am using right now and in "documentos" tab are all the input type file
here is my script
<?php
//----------------------------------------- start edit here ---------------------------------------------//
$script_location = "http://www.proderma.org/"; // location of the script
$maxlimit = 8388608; // maxim image limit
$folder = "uploads/foto_doc"; // folder where to save images
// requirements
$minwidth = 200; // minim width
$minheight = 200; // minim height
$maxwidth = 4608; // maxim width
$maxheight = 3456; // maxim height
$thumb3 = 1; // allow to create thumb n.3
// allowed extensions
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG', '.docx');
//----------------------------------------- end edit here ---------------------------------------------//
// check that we have a file
if((!empty($_FILES["uploadfile"])) && ($_FILES['uploadfile']['error'] == 0)) {
// check extension
$extension = strrchr($_FILES['uploadfile']['name'], '.');
if (!in_array($extension, $extensions)) {
echo 'wrong file format, alowed only .png , .gif, .jpg, .jpeg
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else {
// get file size
$filesize = $_FILES['uploadfile']['size'];
// check filesize
if($filesize > $maxlimit){
echo "File size is too big.";
} else if($filesize < 1){
echo "File size is empty.";
} else {
// temporary file
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
// capture the original size of the uploaded image
list($width,$height) = getimagesize($uploadedfile);
// check if image size is lower
if($width < $minwidth || $height < $minheight){
echo 'Image is to small. Required minimum '.$minwidth.'x'.$minheight.'
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else if($width > $maxwidth || $height > $maxheight){
echo 'Image is to big. Required maximum '.$maxwidth.'x'.$maxheight.'
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else {
// all characters lowercase
$filename = strtolower($_FILES['uploadfile']['name']);
// replace all spaces with _
$filename = preg_replace('/\s/', '_', $filename);
// extract filename and extension
$pos = strrpos($filename, '.');
$basename = substr($filename, 0, $pos);
$ext = substr($filename, $pos+1);
// get random number
$rand = time();
// image name
$image = $basename .'-'. $rand . "." . $ext;
// check if file exists
$check = $folder . '/' . $image;
if (file_exists($check)) {
echo 'Image already exists';
} else {
// check if it's animate gif
$frames = exec("identify -format '%n' ". $uploadedfile ."");
if ($frames > 1) {
// yes it's animate image
// copy original image
copy($_FILES['uploadfile']['tmp_name'], $folder . '/' . $image);
} else {
// create an image from it so we can do the resize
switch($ext){
case "gif":
$src = imagecreatefromgif($uploadedfile);
break;
case "jpg":
$src = imagecreatefromjpeg($uploadedfile);
break;
case "jpeg":
$src = imagecreatefromjpeg($uploadedfile);
break;
case "png":
$src = imagecreatefrompng($uploadedfile);
break;
}
if ($thumb3 == 1){
// create third thumbnail image - resize original to 125 width x 125 height pixels
$newheight = ($height/$width)*600;
$newwidth = 600;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// write thumbnail to disk
$write_thumb3image = $folder .'/thumb3-'. $image;
switch($ext){
case "gif":
imagegif($tmp,$write_thumb3image);
break;
case "jpg":
imagejpeg($tmp,$write_thumb3image,100);
break;
case "jpeg":
imagejpeg($tmp,$write_thumb3image,100);
break;
case "png":
imagepng($tmp,$write_thumb3image);
break;
}
}
// all is done. clean temporary files
imagedestroy($src);
imagedestroy($tmp);
echo "<script language='javascript' type='text/javascript'>window.top.window.formEnable();</script>
<div class='clear'></div>";
}
}
}
}
// database connection
include('include/config.php');
$stmt = $conn->prepare('INSERT INTO INGRESOS (nombre,dui,nit,direccion,curriculum,pais,departamento,ciudad,telefono,email,universidad,diploma,jvpm,especializacion,diploma_esp,foto,website,contacto)
VALUES (:nombre,:dui,:nit,:direccion,:curriculum,:pais,:departamento,:ciudad,:telefono,:email,:universidad,:diploma,:jvpm,:especializacion,:diploma_esp,:foto,:website,:contacto)');
$stmt->execute(array(':nombre' => $nombre,':nit' => $nit,':direccion' => $direccion,':curriculum' => $path,':pais' => $pais,':departamento' => $departamento,':ciudad' => $ciudad,':departamento' => $departamento,':ciudad' => $ciudad,':telefono' => $telefono,':email' => $email,':universidad' => $universidad,':diploma' => $path1,':jvpm' => $jvpm,':especializacion' => $especializacion,':diploma_esp' => $path2,':foto' => $write_thumb3image,':website' => $website,':contacto' => $contacto));
echo 'Afiliación ingresada correctamente.';
$dbh = null;
}
// error all fileds must be filled
} else {
echo '<div class="wrong">You must to fill all fields!</div>'; }
?>
the files I need save only the path, so I have this:
:curriculum' => $path
:diploma' => $path1
:diploma_esp' => $path2
:foto' => $write_thumb3image
I don´t know if is possible these...I hope it can be.
Best Regards!
Include multiple file fields
<input type="file" name="file[0]" />
<input type="file" name="file[1]" />
<input type="file" name="file[2]" />
<input type="file" name="file[3]" />
Wrap a foreach around your save script
// set up your paths
$paths=array($path, $path1, $path2, $write_thumb3image);
// 0 1 2 3
// use them as your loop
foreach ($paths as $i=>$path){ // <- use an index $i
// *** save to $path.'/'.$your_image_name.$image_ext
// as Phillip rightly pointed out, $_FILES is different
// so using your index, pick out the bits from the $_FILES arary
$name=$_FILES['file']['name'][$i];
$type=$_FILES['file']['type'][$i];
$tmp_name=$_FILES['file']['tmp_name'][$i];
$size=$_FILES['file']['size'][$i];
$error=$_FILES['file']['error'][$i];
$extension = strrchr($name, '.'); // NB the file name does not mean that's the true extension
....
}
Untested