给你个参考:
HTML页面:
上传文件 上传
PHP页面:
$newfile = "";
$sub = "";
if(!empty($_POST['submit'])=="submit"){
$sub = $_POST['submit'];
if($_FILES['upload']['error']>0){
//echo "ERROR:".$_FILES['upload']['error']."";
}else{
$upload_dir = "upload";
$filename = $_FILES['upload']['name'];
if(!is_dir($upload_dir)){
if(!mkdir($upload_dir)){
echo "";
exit;
}
}else{
$str = "";
for($i=0;$i<4;$i++){
$str .=mt_rand(0,9);
}
$farr = explode(".",$filename);
$hz = end($farr);
$newfile = $upload_dir."/".time()."_".$str.".".$hz;
move_uploaded_file($_FILES['upload']["tmp_name"],$newfile);
}
}
}
?>
文件上传