上传文件到新浪云Storage的方法

上传文件到新浪云Storage的方法,兼容本地服务器

            if (!empty($_FILES['sharepic']['name'])){
                $tmp_file = $_FILES['sharepic']['tmp_name'];
                $file_types = explode(".", $_FILES['sharepic']['name']);
                $file_type = $file_types[count($file_types) - 1];
        
                /*设置上传路径*/
                if (isset($_SERVER['HTTP_APPNAME'])){//SAE
                    $file_name = time().".".$file_type;
                    $s = new \SaeStorage();
                    $s->upload('rpunion', $file_name, $tmp_file);
                    $file_name = $s->getUrl('rpunion', $file_name);
                }else {
                    $file_name = "Uploads/".time().".".$file_type;
                    if (!move_uploaded_file($tmp_file, $file_name)){
                        $this->error ('文件上传失败,请关注方倍工作室账号');
                    }
                    $file_name = "http://".$_SERVER['SERVER_NAME']."/".$file_name;
                }
                // var_dump($file_name);
                $Form->sharepic = $file_name;
            }else{
                
            }

 

posted @ 2019-07-11 23:06  方倍工作室  阅读(885)  评论(0编辑  收藏  举报