PHP code example of hzz / free-pic

1. Go to this page and download the library: Download hzz/free-pic 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/ */

    

hzz / free-pic example snippets



// 配置项
$config = [
    'sm' => [ // sm 需要token ,不使用可无须配置
        "token" => "Yuc4fb0BuwsOnd4y7R0zFp0tVGkxYgRa22"
    ],
    'debug' => true,
    'log' => [
        'name' => 'img_hosting',
        'file' => __DIR__ . '/img_hosting.log',
        'level' => 'debug',
        'permission' => 0777,
    ],
];

$params = [
    "filepath" => "图片的绝对路径",
];
// 实例化
$freePic = new \Hzz\FreePic($config);
// 上传 , 同理 可用 ->sm , ->freeImageHost , ->catBox 调用对应的服务
$res = $freePic->imgBB->upload($params); // 这里返回的是对应图床服务器返回的上传结果数据。
// getUrl方法 可获取实际
$url = $freePic->imgBB->getUrl($res);