ctrl
or shift
key.
<form action='uploadck.php' method=post target='myiframe' enctype='multipart/form-data' >
<input type=hidden name=todo value='upload'>
<table >
<tr ><td class='data'>Images</td><td>
<input type=file name='file_up[]' multiple>
<input type=submit value='Upload Images'></td></tr>
</table>
</form>
Note the attribute multiple inside upload tag. With this we can press ctrl key in our keyboard and select multiple file at same time. We can select files as many as we want. The same will be available for the backend PHP script.set_time_limit (0);
$max_file_size=2000; // This is in KB
@$todo=$_POST['todo']; // getting other form data ( optional )
$path_upload="upload/";
$path_thumbnail="upload_thumb/";
/// for thumbnail image size //
$n_width=100;
$n_height=100;
$required_image_width=890; // Width of resized image after uploading
We will get a global array inside our PHP script to know about the files to be uploaded.
$_FILES['file_up']
We will check all files by looping and uploading them to server.
while(@list($key,$value) = each($_FILES['file_up']['name']))
{
$file_name=$value;
$add = $path_upload.$file_name;
// check file extensions for allowing images only
// create thumbnail
// Resize the image if size is more
// display the thumbnail image ( for iframe inside upload.php)
}
Allow only if images by checking file extensions
if (!($_FILES[file_up][type][$key] =="image/jpeg" OR $_FILES[file_up][type][$key] =="image/gif"))
{$msg=$msg."Your uploaded file must be of JPG or GIF. ";
$msg.="($file_name) Other file types are not allowed<BR>";
$file_upload_flag="false";
}else{
copy($_FILES['file_up']['tmp_name'][$key], $add);//upload the file to the server
chmod("$add",0777); // set permission to the file.
/// Continue with thumbnail creation and resizing if required
}
Creating Thumbnail images
//////////ThumbNail creation //////////////////
if(file_exists($add)){
$tsrc=$path_thumbnail.$file_name;
$im=ImageCreateFromJPEG($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod("$tsrc",0777);
}// end of if
////////Ending of thumb nail ////////
Resize the image if size is more
//// Resize original image if width is more than 890 /////
if($required_image_width < $width){// width is set at starting of this page
$adjusted_height=round(($required_image_width/$width) * $height);
//echo $adjusted_height . " - ".$height."<br>";
$im=ImageCreateFromJPEG($add);
$newimage=imagecreatetruecolor($required_image_width,$adjusted_height);
imageCopyResized($newimage,$im,0,0,0,0,$required_image_width,$adjusted_height,$width,$height);
ImageJpeg($newimage,$add);
chmod("$add",0777);
} // end of if width of image is more
<form action='uploadck.php' method=post target='myiframe' enctype='multipart/form-data' >
<input type=hidden name=todo value='upload'>
<table >
<tr ><td class='data'>Images</td><td>
<input type=file name='file_up[]' multiple>
<input type=submit value='Upload Images'></td></tr>
</table>
</form>
<iframe name='myiframe' src='uploadck.php' style="overflow: hidden; height: 100%; width: 100%; position: absolute;" frameBorder=\"0\">
</iframe>
As this script allows more than one file to upload so this script is likely to take more time than normal execution time. So it is better to set a higher value to manage maximum script execution time for this script.
meera venugopal | 17-09-2014 |
example code please |