如何给上传文件加限制 检查是否是图片检查是否重名 或者改名字,但不知道该怎么弄不改php.ini限制大小上传 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 提交表单后,$_FILES['控件名称'] 中保存着文件的相关信息。做相应的判断就可。 /*功能说明:上传文件变量说明:$fileinfo:文件信息 $path:需要存放的路径 $fname:文件名 $size:允许上传的文件大小(正整数) $uptype:允许上传的文件类型列表(数组)例:$a=array('image/jpg','image/jpeg','image/png','image/pjpeg','image/gif','image/bmp','application/x-shockwave-flash','image/x-png');file_upload($_FILES["pic"],"upfile/news/");*/function file_upload($fileinfo,$path,$fname="",$size=10000000,$uptype=""){ if(!empty($fileinfo[name])){ if($uptype!="" && !in_array($fileinfo["type"],$uptype)){//检查文件类型 echo ("文件格式错误,文件上传失败"); } else if($fileinfo['size']>(int)($size) || $fileinfo['size']<=0){//允许上传的文件大小 echo ("文件太大或未知,文件上传失败"); } else{ if($fname!=""){ $file_path=$path.$fname; } else{ $text=explode(".",$fileinfo[name]);//分割文件名 $length=sizeof($text); $file_path=$path.rand(0,1000).gmdate("Ymdhis").".".strtolower($text[(int)($length-1)]); if(file_exists($file_path)){//判断重名 echo ("同名文件已经存在了"); } } move_uploaded_file($fileinfo['tmp_name'],$file_path); return $file_path; } } else{ return ""; }} swfupload 查询用户回帖的标题和发帖时间 在线等`!!!!! 输出目录 插入php变量到mysql的表中 急!上传图片的问题! php 兼职调查 在linux下调试时,session出了问题!急!在线等待! 在PHP如何设置和使用网页间的公共变量? 如何把$Array的内容写到文件 thinkphp下,快钱支付接口怎么写。 mysql条件使用or查询不会触发索引? PHP模拟登陆网站出现会话超时
/*
功能说明:上传文件
变量说明:$fileinfo:文件信息 $path:需要存放的路径 $fname:文件名 $size:允许上传的文件大小(正整数) $uptype:允许上传的文件类型列表(数组)
例:
$a=array(
'image/jpg',
'image/jpeg',
'image/png',
'image/pjpeg',
'image/gif',
'image/bmp',
'application/x-shockwave-flash',
'image/x-png'
);
file_upload($_FILES["pic"],"upfile/news/");
*/
function file_upload($fileinfo,$path,$fname="",$size=10000000,$uptype=""){
if(!empty($fileinfo[name])){
if($uptype!="" && !in_array($fileinfo["type"],$uptype)){//检查文件类型
echo ("文件格式错误,文件上传失败");
}
else if($fileinfo['size']>(int)($size) || $fileinfo['size']<=0){//允许上传的文件大小
echo ("文件太大或未知,文件上传失败");
}
else{
if($fname!=""){
$file_path=$path.$fname;
}
else{
$text=explode(".",$fileinfo[name]);//分割文件名
$length=sizeof($text);
$file_path=$path.rand(0,1000).gmdate("Ymdhis").".".strtolower($text[(int)($length-1)]);
if(file_exists($file_path)){//判断重名
echo ("同名文件已经存在了");
}
}
move_uploaded_file($fileinfo['tmp_name'],$file_path);
return $file_path;
}
}
else{
return "";
}
}