看了网上一些前辈的代码,太复杂了,有点眼晕,毕竟俺是新手啊。能不能写的简单点,最好有注释让俺能看懂,谢谢啦。
//接收上传的文件
foreach($_FILES as $file)
{
$tempFileName = $file['tmp_name'];//上传文件的临时路径
}
/把图片移动到服务器制定路径
$img = '/var/www/html/picture/test.jpg';
move_uploaded_file($tempFileName, $img);
//缩放比例
$ratio = 0.5;
//修改尺寸 至于各个函数是干嘛的,google一下吧
$imagedata = getimagesize($img);
$olgWidth = $imagedata[0];
$oldHeight = $imagedata[1];
$newWidth = $olgWidth * $ratio;
$newHeight = $oldHeight * $ratio;
$image = imagecreatefromjpeg($img);
$thumb = imagecreatetruecolor ($newWidth, $newHeight);
imagecopyresized ($thumb, $image, 0, 0, 0, 0, $newWidth, $newHeight, $olgWidth, $oldHeight);
imagejpeg($thumb, $img);
imagedestroy($thumb);
imagedestroy($image);
foreach($_FILES as $file)
{
$tempFileName = $file['tmp_name'];//上传文件的临时路径
}
/把图片移动到服务器制定路径
$img = '/var/www/html/picture/test.jpg';
move_uploaded_file($tempFileName, $img);
//缩放比例
$ratio = 0.5;
//修改尺寸 至于各个函数是干嘛的,google一下吧
$imagedata = getimagesize($img);
$olgWidth = $imagedata[0];
$oldHeight = $imagedata[1];
$newWidth = $olgWidth * $ratio;
$newHeight = $oldHeight * $ratio;
$image = imagecreatefromjpeg($img);
$thumb = imagecreatetruecolor ($newWidth, $newHeight);
imagecopyresized ($thumb, $image, 0, 0, 0, 0, $newWidth, $newHeight, $olgWidth, $oldHeight);
imagejpeg($thumb, $img);
imagedestroy($thumb);
imagedestroy($image);
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2018-04-13
方法
1,上传地址随机生成,指向到不同的服务器,以达到每个服务器上传压力和存储负载均衡
2,上传服务器上有事件监听事件,有新文件上传,可以使用rsync等协议将文件推到其它服务器
3,通过CDN等方式在有需要的时候,将文件同步到其它服务器本回答被网友采纳
1,上传地址随机生成,指向到不同的服务器,以达到每个服务器上传压力和存储负载均衡
2,上传服务器上有事件监听事件,有新文件上传,可以使用rsync等协议将文件推到其它服务器
3,通过CDN等方式在有需要的时候,将文件同步到其它服务器本回答被网友采纳
第2个回答 2013-06-29
一般的框架或者cms应该都有这个功能
第3个回答 2013-06-28
需要在PHP代码里面实现吧