//因为太长,这是接上面的!!
$new_width = 80;
$new_height = 100;if (mysql_num_rows($result) == 1)
{
$row = mysql_fetch_array($result);
$oldfoto = $row["fotopath"];
unlink($oldfoto);
$oldfoto = $row["thumbpath"];
unlink($oldfoto);
move_uploaded_file($_FILES['userphoto']['tmp_name'], $newname);
chmod($newname, 0644);
list($width_orig, $height_orig) = getimagesize($newname);
if ($width_orig > $new_width || $height_orig > $new_height)
{
if ($ext == ".jpg" || $ext == ".jpeg" || $ext == ".JPG" || $ext == ".JPEG")
{
$srcimg = ImageCreateFromJPEG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageJPEG($dest_img, $thumbname, 100);
}elseif ($ext == ".png" || $ext == ".PNG")
{
$srcimg = ImageCreateFromPNG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImagePNG($dest_img, $thumbname);
}elseif ($ext == ".gif" || $ext == ".GIF")
{
$srcimg = ImageCreateFromGIF($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageGIF($dest_img, $thumbname);
} elseif ($ext == ".bmp" || $ext == ".BMP")
// {
// if ($new_width && ($width_orig < $height_orig))
// $new_width = ($new_height / $height_orig) * $width_orig;
// else
// $new_height = ($new_width / $width_orig) * $height_orig;
// Resample
// $dest_img = imagecreatetruecolor($new_width, $new_height);
// imagecopyresampled($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
// ImageWBMP($dest_img, $thumbname);
copy ($newname, $thumbname);
// }
}
else
copy ($newname, $thumbname);
$result = mysql_query("update photos set
fotopath = '$newname',
thumbpath = '$thumbname',
description = '$description'
WHERE username='$valid_user' AND fotoid = '$fotoid'"); if (!$result)
db_error();
}
else
{
move_uploaded_file($_FILES['userphoto']['tmp_name'], $newname);
chmod($newname, 0644);
list($width_orig, $height_orig) = getimagesize($newname);
if ($width_orig > $new_width || $height_orig > $new_height)
{
if ($ext == ".jpg" || $ext == ".jpeg" || $ext == ".JPG" || $ext == ".JPEG")
{
$srcimg = ImageCreateFromJPEG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageJPEG($dest_img, $thumbname, 100);
}elseif ($ext == ".png" || $ext == ".PNG")
{
$srcimg = ImageCreateFromPNG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImagePNG($dest_img, $thumbname);
}elseif ($ext == ".gif" || $ext == ".GIF")
{
$srcimg = ImageCreateFromGIF($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageGIF($dest_img, $thumbname);
}elseif ($ext == ".bmp" || $ext == ".BMP")
{
copy ($newname, $thumbname);
}
}
else
copy ($newname, $thumbname);
$result = mysql_query("insert into photos values ('','$valid_user','$fotoid', '$newname','$thumbname', '$description')"); if (!$result)
db_error();
}session_unregister ("fotoerrors");header("Location: profilefoto.php");?>
$new_width = 80;
$new_height = 100;if (mysql_num_rows($result) == 1)
{
$row = mysql_fetch_array($result);
$oldfoto = $row["fotopath"];
unlink($oldfoto);
$oldfoto = $row["thumbpath"];
unlink($oldfoto);
move_uploaded_file($_FILES['userphoto']['tmp_name'], $newname);
chmod($newname, 0644);
list($width_orig, $height_orig) = getimagesize($newname);
if ($width_orig > $new_width || $height_orig > $new_height)
{
if ($ext == ".jpg" || $ext == ".jpeg" || $ext == ".JPG" || $ext == ".JPEG")
{
$srcimg = ImageCreateFromJPEG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageJPEG($dest_img, $thumbname, 100);
}elseif ($ext == ".png" || $ext == ".PNG")
{
$srcimg = ImageCreateFromPNG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImagePNG($dest_img, $thumbname);
}elseif ($ext == ".gif" || $ext == ".GIF")
{
$srcimg = ImageCreateFromGIF($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageGIF($dest_img, $thumbname);
} elseif ($ext == ".bmp" || $ext == ".BMP")
// {
// if ($new_width && ($width_orig < $height_orig))
// $new_width = ($new_height / $height_orig) * $width_orig;
// else
// $new_height = ($new_width / $width_orig) * $height_orig;
// Resample
// $dest_img = imagecreatetruecolor($new_width, $new_height);
// imagecopyresampled($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
// ImageWBMP($dest_img, $thumbname);
copy ($newname, $thumbname);
// }
}
else
copy ($newname, $thumbname);
$result = mysql_query("update photos set
fotopath = '$newname',
thumbpath = '$thumbname',
description = '$description'
WHERE username='$valid_user' AND fotoid = '$fotoid'"); if (!$result)
db_error();
}
else
{
move_uploaded_file($_FILES['userphoto']['tmp_name'], $newname);
chmod($newname, 0644);
list($width_orig, $height_orig) = getimagesize($newname);
if ($width_orig > $new_width || $height_orig > $new_height)
{
if ($ext == ".jpg" || $ext == ".jpeg" || $ext == ".JPG" || $ext == ".JPEG")
{
$srcimg = ImageCreateFromJPEG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageJPEG($dest_img, $thumbname, 100);
}elseif ($ext == ".png" || $ext == ".PNG")
{
$srcimg = ImageCreateFromPNG($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImagePNG($dest_img, $thumbname);
}elseif ($ext == ".gif" || $ext == ".GIF")
{
$srcimg = ImageCreateFromGIF($newname);
if ($new_width && ($width_orig < $height_orig))
$new_width = ($new_height / $height_orig) * $width_orig;
else
$new_height = ($new_width / $width_orig) * $height_orig;
// Resample
$dest_img = imagecreatetruecolor($new_width, $new_height);
imageCopyResampleBicubic($dest_img, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
// Output
ImageGIF($dest_img, $thumbname);
}elseif ($ext == ".bmp" || $ext == ".BMP")
{
copy ($newname, $thumbname);
}
}
else
copy ($newname, $thumbname);
$result = mysql_query("insert into photos values ('','$valid_user','$fotoid', '$newname','$thumbname', '$description')"); if (!$result)
db_error();
}session_unregister ("fotoerrors");header("Location: profilefoto.php");?>
解决方案 »
- thinkphp,TOKEN_ON关闭了还是有令牌
- PHP字符串加密解密问题
- 请帮检查下代码,第一个循环问题出在哪?
- 项目改为改为b/s架构,能否给点建议?
- 高手帮忙看一下图片显示问题
- PHP开发的国内一流管理软件平台,现免费,可作为基于PHP的管理软件开发环境
- 怎样才能让页面随着IFRAME的大小而变化?
- 怎样做一个统计别的网站链接到我们网站的程序呢?进来说说!~谢谢~
- 请教怎样把Web页上的数据库查询结果按显示格式存储成本地的Excel文件(服务器是Unix系统)?
- 请教生日,性别,地址如何存储和读取(选择模式!)
- http://www.newstepnanhai.com.cn/
- 问一个简单的问题
$ext = strtolower(strrchr($_FILES['userphoto']['name'], ".")); //取得上传文件的后缀
if(! in_array($ext,$img_ext)) //检查是否允许
die("图片格式错");
$image = substr(strrchr($_FILES['userphoto']['name'],0,strlen($ext)).'.jpg'; //构造目标文件名
$im = imagecreatefromstring($_FILES['userphoto']['tmp']); //读取上传文件
imagejpeg($im,$image); //写到目标文件
$im = imagecreatefromstring($_FILES['userphoto']['tmp']); //读取上传文件
改为$imgstream = file_get_contents($_FILES['userphoto']['tmp']); //读取上传文件
$im = imagecreatefromstring($imgstream); //加载图片
//生成缩略图
// 本函数从源文件取出图象,设定成指定大小,并输出到目的文件
// 源文件格式:gif,jpg,jpe,jpeg,png
// 目的文件格式:jpg
// 参数说明:$srcFile:源文件 $dstFile:目标文件 $dstW:目标图象宽度 $dstH:目标图象高度
function makethumb($srcFile,$dstFile,$dstW,$dstH) {
$data = GetImageSize($srcFile);
switch ($data[2]) {
case 1:
$im = @ImageCreateFromGIF($srcFile);
break;
case 2:
$im = @ImageCreateFromJPEG($srcFile);
break;
case 3:
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$ratio = max($srcW/$dstW,$srcH/$dstH);
$dstW = ($srcW / $ratio);
$dstH = ($srcH / $ratio);
$ni=ImageCreateTrueColor($dstW,$dstH); $dst_img = imagecreate($dstW, $dstH);
imagecopyresized($ni, $im, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
ImageJPEG($ni,$dstFile);//生成JPG图片。如果你要把图片直接输出到浏览器, 那么把第二个参数去掉,并用header()函数指定mine类型
ImageDestroy($im);
ImageDestroy($ni);
}
这样的函数好象并不是初装就有的吧.我试过,好象我的PHP系统里就没有.