# file
# File upload
File upload hasbuilt-in cloud storage function, only need to call the interface can be! Here's how --
- Introduce namespace use sunphp\file\SunFile
- upload a file using the SunFile::upload() method
- Save the uploaded files in the root directory /attachment/ directory
- Development attention! The first argument is the file_name value in $_FILES
use sunphp\file\SunFile;
/* 前端默认入口示例 */
class File {
public function upload(){
/*
参数1:$_FILES里面的file_name值
参数2:文件的类型,支持'image', 'audio','voice', 'video','file'
参数3:(可选)是否远程上传,默认ture,检查云存储并远程上传
参数4:(可选)是否远程上传后,删除本地文件,默认true,删除本地文件。
*/
// 图片上传
$res = SunFile::upload('file_img', "image");
// 音频上传
$res = SunFile::upload('file_audio', "audio");
// 视频上传
$res = SunFile::upload('file_video', "video");
//文件上传
$res = SunFile::upload('file_file', "file");
// 上传后的文件地址
echo $res['path'];
//获取附件地址(本地地址/云存储地址)
$attachurl=SunFile::attachurl();
// 获取完整的文件地址
$file_url=$attachurl.$res['path'];
echo $file_url;
}
}
# Gets attachurl
Obtain the attachment url. If cloud storage is disabled, return the local address; otherwise, return the remote cloud storage url
- Introduce namespace use sunphp\file\SunFile
- Use the SunFile::attachurl() method to obtain storage addresses
- Use attachurl+ file addresses stored in the application to concatenate complete file urls
//获取附件地址(本地地址/云存储地址)
$attachurl=SunFile::attachurl();
// 获取完整的文件地址
$file_url=$attachurl.$res['path'];
echo $file_url;