mam taki upload php do upladowaniu kilku plików na raz i chodzi o sprawdzenie co z nim jest nie tak to raz a dwa zrobić przechwytywanie nazw do bazy danych
plik upload.class.php
<? /////////////////////////////////////// //multi-files upload class //author:paul.ren //e-mail:rsr_cn@yahoo.com.cn //website:www.yawill.com //create:2004-6-22 09:56 //modify: //////////////////////////////////////// class ClsUpload{ var $max_upload_size = "1048576"; //max upload file byte (1M) var $_FILES = ""; //post files var $overwrite = "1"; //is over write var $mode = 0777; //upload file mode var $error = ""; function ClsUpload(){ $this->_FILES = $_FILES; } function uploadfile($srcfile,$dstfile){ if($this->overwrite){ }else return 1; } $isok = @chmod($dstfile,$this->mode) or $this->error .= is_file($dstfile)."change permissions for:$dstfile<br>"; return $isok; } function save($field,$dir,$file_name=""){ $size = $this->_FILES[$field]['size']; if($size>0 && $size<=$this->max_upload_size){ $this->error = $this->_FILES[$field]['error']; $tmp_file = $this->_FILES[$field]['tmp_name']; $file_type = $this->_FILES[$field]['type']; if(!$file_name) $file_name = $this->_FILES[$field]['name']; $isok = $this->uploadfile($tmp_file,$save_path_file); return $isok; }else if($size>$this->max_upload_size){ $this->error .= "file size($size) exceeds max file size: $this->max_upload_size<br>"; }else if($size==0) $this->error .= "File size is 0 bytes<br>"; return 0; } function save_as($field,$pathfile){ return $this->save($field,$dir,$filename); } function mult_save($field,$dir){ $field_names = $this->_FILES[$field]['name']; if(!$file_name) continue; $tmp_file = $this->_FILES[$field]['tmp_name'][$key]; $file_size = $this->_FILES[$field]['size'][$key]; if($file_size>0 && $file_size<=$this->max_upload_size){ $isok = $this->uploadfile($tmp_file,"$dir/$file_name"); }else if($file_size>$this->max_upload_size){ $this->error .= "$file_name:file size exceeds max file size: $this->max_upload_size<br>"; }else $this->error .= "$file_name:File size is 0 bytes<br>"; } }else { return $this->save($field,$dir); } return $isok; } function mult_save_as($field,$dir,$prefix="up_"){ $field_names = $this->_FILES[$field]['name']; if(!$fname) continue; $tmp_file = $this->_FILES[$field]['tmp_name'][$key]; $file_size = $this->_FILES[$field]['size'][$key]; if($file_size>0 && $file_size <= $this->max_upload_size){ $isok = $this->uploadfile($tmp_file,"$dir/$file_name"); }else if($file_size>$this->max_upload_size){ $this->error .= "$file_name:file size exceeds max file size: $this->max_upload_size<br>"; }else $this->error .= "$file_name:File size is 0 bytes<br>"; } }else { return $this->save($field,$dir,$filename); } return $isok; } function p($data){ } } ?>
oraz plik index.php
<? //upload multi-files use mult_save_as method require "./upload.class.php"; if($HTTP_POST_VARS[Submit]){ $upload = new ClsUpload(); $upload->mult_save_as("file",".","php_"); $upload->p($upload); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>upload file</title> </head> <body bgcolor="#E5E5E5" text="#000000" link="#006699" vlink="#5493B4"> <form name="form1" method="post" enctype="multipart/form-data" > <input name="file[]" type="file" ><br/> <input name="file[]" type="file" ><br/> <input name="file[]" type="file" ><br/> <input type="submit" name="Submit" value="Submit"> </form> </body> </html>