谢谢唠叨大哥,本来怕代码太乱,去掉了table的代码,这个是完整的,在我电脑里可以运行的,麻烦请帮忙看看,谢谢!万分感谢!!===================================================================<?
if ($_POST['uploadimg'])
{
$mulu='usericon';//目录 if (file_exists($mulu)) {
} else {
mkdir ($mulu);
} if(isset($_FILES['newpic']))
{
$pt=split('/',$_FILES['newpic']['type']);
//print_r($pt); //Array ( [0] => application [1] => octet-stream ) 
if($pt[0]!='image'){
echo "<script>alert('你传的不是图片'); </script>";
  echo "<meta http-equiv=refresh content='0; url=usericon.php'>";
exit();
}else{
$img_dir=$mulu."/"; //$dt = date('YmdHis', time());
$pic_path = "images";
$pname = $_FILES['newpic']['name'];
$ptype = $_FILES['newpic']['type'];
$psize = $_FILES['newpic']['size'];
if($ptype=="image/gif"){
$the_img = $uid.'.gif';
}
if($ptype=="image/pjpeg"){
      $the_img = $uid.'.jpg';
}
if($ptype!="image/gif"&&$ptype!="image/pjpeg"){
      echo"图片类型不对";
  echo "<meta http-equiv=refresh content='0; url=setting.php'>";
      exit();
}
if($psize > 200000){
echo"大小超过限制";
exit();
}
$local_file = "$the_img";
//rename ( $newpic, $the_img );
if(copy($_FILES['newpic']['tmp_name'],"$img_dir".$local_file)){
/*echo "<script>alert('图片上传成功!'); </script>";*/


//--resize image start
// Set a maximum height and width
$width = 48;
$height = 48;

// Content type
//header('Content-type: image/jpeg');

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($local_file);

if ($width && ($width_orig < $height_orig)) {
    $width = ($height / $height_orig) * $width_orig;
} else {
    $height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($local_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output
imagejpeg($image_p, null, 100);
//-- resize image over

$a=strlen($_SERVER['PHP_SELF'])-12;//根据本页文件名更改此处数字
$b=substr($_SERVER['PHP_SELF'],1,$a);
$imgurl="http://".$_SERVER['HTTP_HOST']."/".$b."$img_dir".$the_img;
$imgdata="$img_dir".$the_img;
}else{
echo "未知错误";
}
}
}
//////////////////////////////////////////////////////////////////写入数据库
$conn = @ mysql_connect($dbhost, $dbuser, $dbpswd);
@ mysql_select_db($dbname, $conn);
mysql_query("set names 'utf8'");
$sql = "UPDATE `USER` SET `usericon` = '$imgdata' WHERE `USER`.`username` = '$username'";
$result = mysql_query($sql);
mysql_close($conn);
}
?>
<table class="tabl">
  <tr>
    <td width="62%" valign="top"><h4>&nbsp;</h4>
<form class="tablidnt" method="post" enctype="multipart/form-data" name="form" id="form">
<br />
<input name="newpic" type="file" id="newpic" size="40" /><p>
        <input type="submit" name="uploadimg" value="上传" />
        <input type="reset" name="Submit2" value="撤销" />
           <a href='javascript:history.back(-1)'></a></p>
    </form>
        <table class="lst">
          <tbody>
            <tr>
              <td valign="top" width="75"></td>
              <td width="517" valign="top"></td>
            </tr>
          </tbody>
      </table></td>
    <td width="4%"></td>
    <td width="34%" valign="top"><h4>&nbsp;</h4>
    </td>
  </tr>
</table> 

解决方案 »

  1.   

    imagecopyresampled
    本函数需要 GD 2.0.1 或更高版本你看看你的服务器安装了GD库没?
      

  2.   

    安装GD库所需的源码包及下载:gd-2.0.33.tar.gz http://www.boutell.com/gd/
    jpegsrc.v6b.tar.gz http://www.ijg.org/
    libpng-1.2.7.tar.tar http://sourceforge.net/projects/libpng/
    zlib-1.2.2.tar.gz http://sourceforge.net/projects/zlib/
    freetype-2.1.9.tar.gz http://sourceforge.net/projects/freetype/
     
    安装步骤:
     
    先安装zlib,freetype,libpng,jpeg,再装GD
     
    1.装zlib
     
    tar zxvf zlib-1.2.2.tar.gz
    cd zlib-1.2.2
    ./configure
    make 
    make install2.安装libpngtar zxvf libpng-1.2.7.tar.tar
    cd libpng-1.2.7
    cd scripts/
    mv makefile.linux ../makefile
    cd ..
    make
    make install
    注意,这里的makefile不是用./configure生成,而是直接从scripts/里拷一个
     
    3.安装freetype
     
    tar zxvf freetype-2.1.9.tar.gz
    cd freetype-2.1.9
    ./configure
    make
    make install 
    4.安装Jpeg
     
    tar zxvf jpegsrc.v6b.tar.gz 
    cd jpeg-6b/
    ./configure –enable-shared
    make
    make test
    make install
    注意,这里configure一定要带–enable-shared参数,不然,不会生成共享库 
    5.安装GD 
    tar zxvf gd-2.0.33.tar.gz 
    cd gd-2.0.33
    ./configure –with-png –with-freetype –with-jpeg
    make install 
      

  3.   

    已经安装了呀 discuz 5.0的水印都可以用的
      

  4.   

    一个简单的问题被你弄复杂了!$uid 在哪里赋值的?
      

  5.   

    谢谢唠叨,$uid 是有值的,在requied 的top.php文件里,有查询数据库,得到$uid的值,现在我的问题是,图片可以上传,但是不能改变大小