PHP code example of yzh52521 / filesystem

1. Go to this page and download the library: Download yzh52521/filesystem library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yzh52521 / filesystem example snippets


 use yzh52521\Filesystem\Facade\Filesystem;
        public function upload(\support\Request $request){
            $file = $request->file('file');
            $result = Filesystem::putFile('webman',$file);
            //文件判断
           
            try {
                    validate(
                        [
                            'image' => [
                                // 限制文件大小(单位b),这里限制为4M
                                'fileSize' => 4 * 1024 * 1000,
                                // 限制文件后缀,多个后缀以英文逗号分割
                                'fileExt'  => 'gif,jpg,png,jpeg'
                            ]
                        ]
                    )->check(['image' => $file]);
                $path = Filesystem::disk('local')->putFile('webman',$file);
             }catch (\yzh52521\validate\exception\ValidateException | \Exception $e){
                print($e->getMessage());
             }
            //获取上传文件
            $fileUrl = Filesystem::url($path);    
            
            //指定选定器外网
            $fileUrl = Filesystem::disk('oss')->url($path); 
         }