进入论坛,发个帖子,试图添加一个附件的时候出现问题了,出现如下错误

检查后发现,原来时忘了开通SAE的Storage服务了,因为在安装的时候,我们顺便把settings['uploadspath']改成了"saestor://uploads"这样的路径,表示上传的文件将保存到Storage的相应位置,所有要先开通服务,再建立一个名为uploads的domain。然后再重新上传附件,成功了。进入SAE的storage管理页面,可以看到刚刚上传的文件了。但是还是有个问题,文件是放在根目录下的,而不是常见的存放在以年月命名的文件夹中,这就需要修改源代码了。
修改inc/functions_upload.php,440行~448行,这里会判断年月文件夹是否存在,不存在则创建,创建不成功则置为空,也就是根目录了,因为SAE是不允许写文件的,所有肯定会失败,修改很简单,把这几行注释掉就可以了。OK,附件添加成功。
但是生成缩略图失败,这回要修改inc/functions_image.php,function generate_thumbnail($file, $path, $filename, $maxheight, $maxwidth)。具体是什么原因暂时还不清楚,这里我先改成用Image服务来做。
在应用根目录下建立文件夹saelib,用来存放官方提供的api。下载saeimage.class.php并存到saelib中。修改function generate_thumbnail如下:
require_once MYBB_ROOT."saelib/saeimage.class.php";function generate_thumbnail($file, $path, $filename, $maxheight, $maxwidth)
{
$imgdesc = getimagesize($file);
$imgwidth = $imgdesc[0];
$imgheight = $imgdesc[1];
$imgtype = $imgdesc[2];
$imgattr = $imgdesc[3];
$imgbits = $imgdesc['bits'];
$imgchan = $imgdesc['channels'];
if($imgwidth == 0 || $imgheight == 0)
{
$thumb['code'] = 3;
return $thumb;
}
if(($imgwidth >= $maxwidth) || ($imgheight >= $maxheight))
{
$scale = scale_image($imgwidth, $imgheight, $maxwidth, $maxheight);
$thumbwidth = $scale['width'];
$thumbheight = $scale['height'];
$format = "jpg";
switch($imgtype)
{
case 1:
$format = "gif";
break;
case 2:
$format = "jpg";
break;
case 3:
$format = "png";
break;
}
$img = new SaeImage(file_get_contents($file));
$img->resize($thumbwidth, $thumbheight);
$new_data = $img->exec($format);
if ($new_data === false)
{
return array("code" => 1);
}
file_put_contents($path."/".$filename, $new_data);
$thumb['code'] = 1;
$thumb['filename'] = $filename;
return $thumb;
}
else
{
return array("code" => 4);
}
}搞定。

2502

被折叠的 条评论
为什么被折叠?



