文件上传和移除文件

=====================
//文件上传处理
function delemp($v){
return $v!='';
}
$upfilename=array_filter($_FILES['upload']['name'],delemp);


$dirname='upload/'.date('Ymd');
if(!is_dir($dirname)){
mkdir($dirname);
}
foreach($upfilename as $k=>$v){
$newpath=$dirname.'/'.mt_rand(10,100).$v;
if(is_uploaded_file($_FILES['upload']['tmp_name'][$k])){
if(!move_uploaded_file($_FILES['upload']['tmp_name'][$k], $newpath)){
echo "<script>alter('文件上传失败')</script>";
exit;
}
}else{
echo "<script>alter('不是上传文件')</script";
}
}
=====================
===========================
//移除文件,和删除目录
function rmdire($dir,$type){
$dirname=opendir($dir);
while(($file=readdir($dirname))!=false){
$filename=$dir.'/'.$file;
if($file!='.'&&$file!='..'){
if(is_dir($filename)){
rmdire($filename,$type);
}
if(!is_array($type)){
$filetype[]=$type;
}else{
$filetype=$type;
}
if(is_file($filename)&&in_array(strrchr($file,'.'),$filetype)){
unlink($filename);
}
}
}
//closedir($dirname);
//rmdir($dir);
}
rmdire('./yy','.php');
===================
/*mkdir('temp/yuguibin/image',0777,true);//递归方式建立;*/

你可能感兴趣的:(文件上传)