Kiến thức là vô biên, vì vậy hãy chia sẻ nó. Trên đây là một số công cụ và source mình sưu tầm được. Mong là nó sẽ hữu ích đối với bạn !
Code Google
Thứ Hai, 6 tháng 5, 2013
Upload nhiều file cùng 1 lúc
html
<form action="demo_form.asp" enctype="multipart/form-data" >
Select images: <input type="file" name="img" multiple>
<input type="submit">
</form>
Function php
forech($_FILE[]){
uploadimg_many
}
function uploadimg_many($vt,$images, $delpic, $thumb, $thumb_width, $upath) {
global $max_size, $width;
if ($delpic == "yes") {
@unlink("".INCLUDE_PATH."".$upath."/".$images."");
@unlink("".INCLUDE_PATH."".$upath."/small_".$images."");
$images = "";
}
if (is_uploaded_file($_FILES['userfile']['tmp_name'][$vt])) {
@unlink("".INCLUDE_PATH."".$upath."/".$images."");
@unlink("".INCLUDE_PATH."".$upath."/small_".$images."");
$images = "";
$realname = $_FILES['userfile']['name'][$vt];
$file_size = $_FILES['userfile']['size'][$vt];
$file_type = $_FILES['userfile']['type'][$vt];
$f_name = end(explode(".", $realname));
$f_extension = strtolower($f_name);
$loaiimg_ext = array("gif","jpg","jpeg","pjpeg","bmp","png");
$loaiimg_mime = array("image/gif", "image/pjpeg", "image/jpeg", "image/bmp", "image/png");
if ($file_size > $max_size) {
info_exit("<br><br><center>"._EROR1." ".$file_size." "._EROR2." $max_size byte.<br><br>"._GOBACK."</center><br><br>");
}
if(!in_array($file_type,$loaiimg_mime) || !in_array($f_extension,$loaiimg_ext)) {
info_exit("<br><br><center>"._EROR6."<br><br>"._GOBACK."</center><br><br>");
}
$datakod = date(U).rand();
$picname = "".$datakod.".nv.".$f_extension."";
if(! @copy($_FILES['userfile']['tmp_name'][$vt], "".INCLUDE_PATH."".$upath."/".$picname."") ) {
if (! move_uploaded_file($_FILES['userfile']['tmp_name'][$vt], "".INCLUDE_PATH."".$upath."/".$picname."")) {
info_exit("<br><br>"._UPLOADFAILED."<br>");
}
}
if (file_exists("".INCLUDE_PATH."".$upath."/".$picname."")) {
$images = $picname;
if ($f_extension == "jpg" AND extension_loaded("gd")) {
$size = @getimagesize("".INCLUDE_PATH."".$upath."/".$images."");
$thc = 0;
if ($size[0] > $width) {
$thc = 1; $sizemoi = $width;
} elseif($size[0] > $thumb_width AND $size[0] < ($thumb_width+20)) {
$thc = 1; $sizemoi = $thumb_width;
}
if ($thc == 1) {
$src_img= ImageCreateFromJpeg("".INCLUDE_PATH."".$upath."/".$images."");
$src_width= ImagesX($src_img);
$src_height= ImagesY($src_img);
$dest_width = $sizemoi;
$dest_height = $src_height/($src_width/$dest_width);
$dest_img=ImageCreateTrueColor($dest_width, $dest_height);
ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
ImageJpeg($dest_img, "".INCLUDE_PATH."".$upath."/".$images."", 90);
ImageDestroy($dest_img);
}
$size = @getimagesize("".INCLUDE_PATH."".$upath."/".$images."");
if($thumb==1 AND $size[0] > $thumb_width) {
$picname_thumb = "small_".$picname."";
if(! @copy($_FILES['userfile']['tmp_name'][$vt], "".INCLUDE_PATH."".$upath."/".$picname_thumb."") ) {
@move_uploaded_file($_FILES['userfile']['tmp_name'][$vt], "".INCLUDE_PATH."".$upath."/".$picname_thumb."");
}
if (file_exists("".INCLUDE_PATH."".$upath."/".$picname_thumb."")) {
$src_img= ImageCreateFromJpeg("".INCLUDE_PATH."".$upath."/".$picname_thumb."");
$src_width= ImagesX($src_img);
$src_height= ImagesY($src_img);
$dest_width = $thumb_width;
$dest_height = $src_height/($src_width/$dest_width);
$dest_img=ImageCreateTrueColor($dest_width, $dest_height);
ImageCopyResampled($dest_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
ImageJpeg($dest_img, "".INCLUDE_PATH."".$upath."/".$picname_thumb."", 90);
ImageDestroy($dest_img);
}
}
}
}
}
return($images);
}
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét