检查是否是图片
检查是否重名  或者改名字,但不知道该怎么弄
不改php.ini限制大小上传

解决方案 »

  1.   

    提交表单后,$_FILES['控件名称'] 中保存着文件的相关信息。做相应的判断就可。
      

  2.   


    /*
    功能说明:上传文件
    变量说明:$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 "";
    }
    }