if ($allow_upload && $attachment && $attachment != "none" && ereg("^php[0-9A-Za-z_.-]+$", basename($attachment))) $upload=1;
else $upload=0;

if ($check && $upload) {
//-----User has uploaded some file-----
if ($attachment_size>$max_upload_size && !in_array($username,$admin_user)) {
$check=0; $status='上传文件超过指定大小';
}else{
$available_ext = explode(' ',$upload_type_inavailable);
$extcount=count($available_ext); $is_ext_allowed=1;
for ($i=0; $i<$extcount; $i++) {
$currentext=$available_ext[$i];
if (eregi("\.\\$currentext$",$attachment_name)) {
   $is_ext_allowed=0; break;
   }
}
if (!$is_ext_allowed) {$check=0; $status='上传文件的类型不符合准则';}
}
}

解决方案 »

  1.   

    如果服务器不支持$attachment_size直接调用,则加上这么一段:
    $attachment=$HTTP_POST_FILES['attachment']['tmp_name'];
    $attachment_name=$HTTP_POST_FILES['attachment']['name'];
    $attachment_size=$HTTP_POST_FILES['attachment']['size'];
      

  2.   

    $MyFile1_name=$_FILES['MyFile1']['name'];//取得名字
    $MyFile1_size=$_FILES['MyFile1']['size'];//取得大小/**
    返回图片扩展名
    */
    function extname($filename) 

    $retval=""; 
    $pt=strrpos($filename, "."); 
    if ($pt) $retval=substr($filename, $pt+1, strlen($filename) - $pt); 
    return ($retval); 
    }
      

  3.   

    我是新手,刚刚写了个上传图片的代码,交流一下$file_path="./pic/";
    $size=round($_FILES['file']['size']/1024,2);
    if($size>500)
    {
    echo "<script>alert('您的图片太大,请重新编辑后再上传!');</script>";
    echo "<script>location.href='upload.php'</script>";
    exit();
    }

    $name=$_FILES['file']['name'];
    $name_array=explode(".",$name);
    $hz=".".$name_array[1];
    $name=time().$hz;

    if(($hz!=".gif")&&($hz!=".png")&&($hz!=".jpg")&&($hz!=".jpeg"))
    {
    echo "<script>alert('您的图片格式不符合要求!');</script>";
    echo "<script>location.href='upload.php';</script>";
    exit();
    }

    if(is_dir($file_path)!=1)
    if(!mkdir($file_path))
    {
    echo "<script>alert('目录创建出现异常,请手动创建!');</script>";
    echo "<script>location.href='upload.php';</script>";
    exit();
    }


    if(@move_uploaded_file($_FILES['file']['tmp_name'],$file_path.$_FILES['file']['name']))
    {
    if(!rename($file_path.$_FILES['file']['name'],$file_path.$name))
    {
    unlink($file_path.$_FILES['file']['name']);
    echo "<script>alert('图片上传时出错!');</script>";
    echo "<script>location.href='upload.php';</script>";
    exit();
    }
    $up_time=date("Y-m-d H:i:s");
    $sql="insert into uploadpic(name,size,up_time) values('".$name."',".$size.",'".$up_time."')";
    if(!mysql_query($sql))
    {
    if(!@unlink($file_path.$name))
    $msg="提交数据出错,请手动删除图片!".$name;
    else
    $msg="提交数据库出错!";
    echo "<script>alert(".$msg.");</script>";
    echo "<script>location.href='upload.php';</script>";
    exit();
    }
    }
    else
    {
    echo "<script>alert('图片上传出错,请稍后重试!');</script>";
    echo "<script>location.href='upload.php';</script>";
    exit();
    }
      

  4.   


    //?片上??理
    $upload_file=$_FILES['upload_file']['tmp_name'];
    //echo $upload_file;    //////////////////////////////////////////////////////////////////////////////
    $upload_file_name=$_FILES['upload_file']['name'];
    $upload_file_size =$_FILES['upload_file']['size'];
    $type=strstr($upload_file_name, '.');
        if($upload_file=="")
          {
           $newname=($bianhao).".jpg"; 
          }
      else
      {
      $newname=($bianhao).".jpg";
      }
    //$newname=$newid.$type;//$intonew2="update mms_news_info set col_image='$newname' where col_id='$newid'";
    //mysql_query($intonew2,$db);if($upload_file){
    $file_size_max = 307200;// 300k限制文件上?最大容量(bytes)
    $store_dir = "giftimages/";// 上?文件的?存位置
    $accept_overwrite = 1;//是否允?覆?相同文件
    // ?查文件大小
    if ($upload_file_size > $file_size_max) {
    echo "對不起,你的檔容量大於規定";
    exit;
    }// ?查??文件
    if (file_exists($store_dir . $upload_file_name) && $accept_overwrite) {
    Echo   "存在相同檔案名的文件,你沒有更新圖片所以默認將採用原有圖片!";
    //exit;
    }//复制文件到指定目?
    if (!move_uploaded_file($upload_file,$store_dir.$newname)) {
    echo "複製檔失敗";
    exit;
    }}
    /**
    Echo   "<p>你上?了文件:";
    echo  $_FILES['upload_file']['name'];
    echo "<br/>";
    //客?端机器文件的原名?。 Echo   "文件的 MIME ?型?:";
    echo $_FILES['upload_file']['type'];
    //文件的 MIME ?型,需要??器提供?信息的支持,例如“image/gif”。 
    echo "<br/>";Echo   "上?文件大小:";
    echo $_FILES['upload_file']['size'];
    //已上?文件的大小,?位?字?。 
    echo "<br/>";Echo   "文件上?后被???存?:";
    echo $_FILES['upload_file']['tmp_name'];
    //文件被上?后在服?端?存的??文件名。 
    echo "<br/>";
    *///} //?片上??理
      

  5.   

    <?$FILENAME=time()."_s";// 生成图片的宽度
    $RESIZEWIDTH=200;// 生成图片的高度
    $RESIZEHEIGHT=200;
    function ResizeImage($im,$maxwidth,$maxheight,$name){
        $width = imagesx($im);
        $height = imagesy($im);
        if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
            if($maxwidth && $width > $maxwidth){
                $widthratio = $maxwidth/$width;
                $RESIZEWIDTH=true;
            }
            if($maxheight && $height > $maxheight){
                $heightratio = $maxheight/$height;
                $RESIZEHEIGHT=true;
            }
            if($RESIZEWIDTH && $RESIZEHEIGHT){
                if($widthratio < $heightratio){
                    $ratio = $widthratio;
                }else{
                    $ratio = $heightratio;
                }
            }elseif($RESIZEWIDTH){
                $ratio = $widthratio;
            }elseif($RESIZEHEIGHT){
                $ratio = $heightratio;
            }
            $newwidth = $width * $ratio;
            $newheight = $height * $ratio;
            if(function_exists("imagecopyresampled")){
                  $newim = imagecreatetruecolor($newwidth, $newheight);
                  imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            }else{
                $newim = imagecreate($newwidth, $newheight);
                  imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            }
            ImageJpeg ($newim,$name . ".jpg");
            ImageDestroy ($newim);
        }else{
            ImageJpeg ($im,$name . ".jpg");
        }
    }if($_FILES['image']['size']){
        if($_FILES['image']['type'] == "image/pjpeg"){
            $im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
        }elseif($_FILES['image']['type'] == "image/x-png"){
            $im = imagecreatefrompng($_FILES['image']['tmp_name']);
        }elseif($_FILES['image']['type'] == "image/gif"){
            $im = imagecreatefromgif($_FILES['image']['tmp_name']);
        }
        if($im){
            if(file_exists("$FILENAME.jpg")){
                unlink("$FILENAME.jpg");
            }
            ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);
            ImageDestroy ($im);
        }
    }?><img src="<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br><form enctype="multipart/form-data" method="post">
    <br>
    <input type="file" name="image" size="50" value="浏览"><p>
    <input type="submit" value="上传图片">
    </form> </body>
    </html>
    这个上传的图片是保存在服务器的根目录里面的,如何更改路径?
      

  6.   

    你应该把其他的函数也贴出来
    或者你查找类似 if(copy($_FILES['file']['tmp_name'], "../$folder/$imagename")
    的地方修改
      

  7.   

    ImageJpeg ($newim,"./upload/$name.jpg");
      

  8.   

    ticks(浓浓咖啡味) 所给出的代码中
     imagecreate() 最好用imagecreatetruecolor()代替