前段时间研究了一天的Kindeditor在SAE上传图片和管理图片,想必大家都碰到过在本地很正常,而在SAE上时,遇到了“上传目录没有写权限”的问题。在SAE上,文件夹是没有写权限的,不要再想着怎么去更改文件夹权限了。根据查找资料,下面我将解决方法总结一下:
2、更改Kindeditor中的上传文件upload_json.php。
(1)、在require_once 'JSON.php';下面添加以下代码:
if(isset($_SERVER['HTTP_APPNAME']))
$issae = true; //是否新浪云平台
else
$issae = false;
$domain = 'kindeditor'; //图片domain名称
(2)、在{检查目录、检查目录写权限}和{创建文件夹}加上if判断,判断是否为sae,当不是SAE才执行原来的代码:if(!$issae);
(3)、{移动文件}加上判断是否为非sae,是非sae就执行原来的代码,若是sae则执行以下代码:
$s = new SaeStorage();
$r = $s->upload( $domain , $new_file_name , $tmp_name);
if(!$r)
alert("新浪云平台上传文件失败,请检查domain设置是否正确。");
$file_url = $s->getUrl( $domain , $new_file_name);
以上三步就可以将图片上传到了SAE的Storage域的kindeditor中了。
3、管理所上传的图片,即Kindeditor的图片空间。修改file_manager_json.php,具体代码如下:
if(isset($_SERVER['HTTP_APPCOOKIE'])){
$s=new SaeStorage();
foreach($s->getList('kindeditor') as $v){ //kindeditor为domain的名称
$list[]=explode('/', $v);
}
$path=isset($_GET['path'])?$_GET['path']:'';
$pathArr=explode('/', $path);
$ceng=count($pathArr)-1;
foreach ($list as $v){
$str='';
for($i=0;$i
$str.=$v[$i].'/';
}
if($str==$path){
$currList[]=$v[$ceng].'{+}'.isset($v[$ceng+1]);
}
}
$currList=array_flip(array_flip($currList));
$i=0;
foreach ($currList as $v){
$info=explode('{+}', $v);
$fileAttr=$s->getAttr('kindeditor',$path.$info[0]);
$result['file_list'][$i]['is_dir']=strpos($info[0],'.')<1;
$result['file_list'][$i]['has_file']=$info[1];
$extarr = array ('gif','jpg','jpeg','png','bmp');
$fileinfo=pathinfo($info[0]);
$file_ext = strtolower ( $fileinfo ['extension'] );
$result['file_list'][$i]['is_photo']=in_array($file_ext, $extarr);
$result['file_list'][$i]['filesize']=$fileAttr['length'];
$result['file_list'][$i]['filetype']=$file_ext;
$result['file_list'][$i]['filename']=$info[0];
$result['file_list'][$i]['datetime']=date('Y-m-d H:i:s',$fileAttr['datetime']);
$i++;
}
$result['moveup_dir_path']=preg_replace ( '/(.*?)[^\/]+\/$/', '$1', $path );
$result['current_dir_path']=$path;
$result['current_url']=$s->getUrl('kindeditor','').$path;
$result['total_count']=$i;
echo json_encode ( $result );
exit;
}
希望对大家有帮助!
另外还有个小知识点:
如果想在上传文件时,放入相应的文件夹下,如图:
$s = new SaeStorage();
$r = $s->upload( $domain , $new_file_name , $tmp_name);
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29774965/viewspace-1335653/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29774965/viewspace-1335653/