PHP code example of fizzday / php-fileupload

1. Go to this page and download the library: Download fizzday/php-fileupload 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/ */

    

fizzday / php-fileupload example snippets




use Fizzday\FileUpload\FileUpload;

// 实例化
$up = new FileUpload();

// ********* 上传本地服务器 *********
$res = $up
    ->host('http://url.com')    // 图片域名前缀, 用于拼接上传图片后的路径, 成为完整的图片链接
    ->type('jpg,png')    // 设置上传类型,默认'jpg,jpeg,gif,png,pdf,bmp,zip,psd,tif';
    ->size('10000')    // 设置允许大小,默认 10000k;
    ->path('assets')    // 设置上传路径,默认 assets;
    ->autoSub('date') // 设置自动子目录,默认为空, 如果执行了该方法则默认位(date函数:日期2017/12/22),可选 sha1/md5 等 hash 函数
    ->upload(); // 执行上传;

if (!$res) die($up->getError());    // 错误信息

print_r($res);



use Fizzday\FileUpload\FileUpload;

// 实例化
$up = new FileUpload();

// ********* 上传远程服务器 *********
$remote = $up
    ->remoteUrl('http://remotehost.com/demo/upload.php')    // 远程地址
    ->path('remote_path')  // 路径
    ->autoSub('date')   // 自动子目录
    ->host('http://remotehost.com/demo')    // 图片地址前缀
    ->remoteUpload(['/tmp/assets/1513144248222219.jpeg']);  // 本地文件

echo $remote;



use Fizzday\FileUpload\FileFacade as File;

$res = File::upload();
$res = File::path()->type()->upload();

if (!$res) die($up->getError());    // 错误信息

print_r($res);