ITPub博客

首页 > 应用开发 > IT综合 > 关于Kindeditor在SAE上传图片和管理图片的解决办法(php)

关于Kindeditor在SAE上传图片和管理图片的解决办法(php)

原创 IT综合 作者:0Littleegg 时间:2014-11-17 09:55:32 0 删除 编辑
前段时间研究了一天的Kindeditor在SAE上传图片和管理图片,想必大家都碰到过在本地很正常,而在SAE上时,遇到了“上传目录没有写权限”的问题。在SAE上,文件夹是没有写权限的,不要再想着怎么去更改文件夹权限了。根据查找资料,下面我将解决方法总结一下:

1、SAE上有自己的云储存Storage,首先要开启Storage,然后新建一个domain,并命名(以下我命名为“kindeditor”)。

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<$ceng;$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; 
}


希望对大家有帮助!
另外还有个小知识点:
如果想在上传文件时,放入相应的文件夹下,如图:
关于Kindeditor在SAE上传图片和管理图片的解决办法(php)

那么在以下代码中,$new_file_name="20141106/".file_name;这样就可以将文件放在了20141106这个文件夹下了。
 $s = new SaeStorage();
  $r = $s->upload( $domain , $new_file_name , $tmp_name);

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29774965/viewspace-1335653/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2014-07-29

  • 博文量
    1
  • 访问量
    7334