谢谢唠叨大哥,本来怕代码太乱,去掉了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> </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> </h4>
</td>
</tr>
</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> </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> </h4>
</td>
</tr>
</table>
解决方案 »
- $php_errormsg在php5.2版本中存在吗?怎么用?
- 请问这是什么情况啊FeedBack.html?Page=2
- 请问PHP中SESSION的有效时间是多长
- 我用smarty输出二维数组,结果页面多了几个数字和“口”。
- 常用的正则提示有缺陷,大家帮忙找找
- 请问PHP用正则表达式字符串,只想保留第一个该如何做?
- 什么函数能调出FTP服务器中的所有目录,就想CUTEFTP这样的,进入一个目录就显示下属的目录和文件。
- 到底哪里有PHPADMIN下载,他主页的下不了!!
- thinkphp怎么跟memache和redis结合呢
- 下列语句该如何设置多条件查询
- 求教正则表达式
- Smarty模板的问题,出现奇怪的东西~~~
本函数需要 GD 2.0.1 或更高版本你看看你的服务器安装了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