PHP code example of love-dj / think-filesystem

1. Go to this page and download the library: Download love-dj/think-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/ */

    

love-dj / think-filesystem example snippets


$file = $this->request->file( 'image' );
      try {
            validate(
                ['image' => [
                        // 限制文件大小(单位b),这里限制为4M
                        'fileSize' => 10 * 1024 * 1000,
                        // 限制文件后缀,多个后缀以英文逗号分割
                        'fileExt'  => 'gif,jpg,png,jpeg'
                    ]
                ])->check( ['image' => $file] );

            $path     = \think\facade\Filesystem::disk( 'public' )->putFile( 'test',$file);
            $url      = \think\facade\Filesystem::disk( 'public' )->url( $path );
            return json( ['path' => $path,'url'  => $url] );
      } catch ( \think\exception\ValidateException $e ) {
            echo $e->getMessage();
     }