PHP code example of yzh52521 / think-filesystem
1. Go to this page and download the library: Download yzh52521/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' );
yzh52521 / think-filesystem example snippets
$file = $this ->request->file( 'image' );
try {
validate(
['image' => [
'fileSize' => 10 * 1024 * 1000 ,
'fileExt' => 'gif,jpg,png,jpeg'
]
])->check( ['image' => $file] );
$path = \yzh52521\filesystem\facade\Filesystem::disk( 'public' )->putFile( 'test' ,$file);
$url = \yzh52521\filesystem\facade\Filesystem::disk( 'public' )->url( $path );
return json( ['path' => $path,'url' => $url] );
} catch ( \think\exception \ValidateException $e ) {
echo $e->getMessage();
}
$contents = Filesystem::get('file.jpg' );
return Filesystem::download('file.jpg' );
return Filesystem::download('file.jpg' , $name, $headers);
$url = Filesystem::url('file.jpg' );
$time = Filesystem::lastModified('file.jpg' );
$path = Filesystem::path('file.jpg' );
Filesystem::put('file.jpg' , $contents);
Filesystem::put('file.jpg' , $resource);
if (! Filesystem::put('file.jpg' , $contents)) {
}
Filesystem::copy('old/file.jpg' , 'new/file.jpg' );
Filesystem::move('old/file.jpg' , 'new/file.jpg' );
use League \Flysystem \Filesystem ;
use Spatie \Dropbox \Client as DropboxClient ;
use Spatie \FlysystemDropbox \DropboxAdapter ;
class AppService extends Service
{
public function boot ()
{
Filesystem::extend('dropbox' , function (App $app, array $config) {
$adapter = new DropboxAdapter(new DropboxClient(
$config['authorization_token' ]
));
return new Filesystem($adapter, $config),
});
}
}