//接收
$username=$_POST['username'];
$fileintro=$_POST['fileintro'];
//echo $username.$fileintro;
//获取文件信息
/* echo "
";<br> print_r($_FILES);<br> echo "
Copier après la connexion
";
*/
//获取文件的大小
$file_size=$_FILES['myfile']['size'];
if($file_size>2*1024*1024){
echo "";
exit();
}
//获取文件类型
$file_type=$_FILES['myfile']['type'];
if($file_type!="image/jpeg" && $file_type!="image/pjpeg"){
echo "文件类型只能是 jpg 格式";
exit();
}
//判断上传是否OK
if(is_uploaded_file($_FILES['myfile']['tmp_name'])){
//得到上传的文件 转存到你希望的目录
$upload_file=$_FILES['myfile']['tmp_name'];
//防止图片覆盖问题,为每个用户建立一个文件夹
$user_path=$_SERVER['DOCUMENT_ROOT']."/file/up/".$username;
if(!file_exists($user_path)){
mkdir ($user_path);
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
//防止用户上传用户名相同的问题
$file_true_name=$_FILES['myfile']['name'];
$move_to_file=$user_path."/".time().rand(1,1000).substr($file_true_name,strripos($file_true_name,"."));
//echo $upload_file.$move_to_file;
//中文要转码
if(move_uploaded_file($upload_file,iconv("utf-8","gb2312","$move_to_file"))){
echo $_FILES['myfile']['name']."上传成功";
}else{
echo "上传失败";
}
}else{
echo "上传失败";
}
?>