上传文件到新浪云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{ }
原文地址:https://www.cnblogs.com/txw1958/p/sae-storage-file-upload.html
时间: 2024-10-10 12:16:58