PHP code example of windwork / storage

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

    

windwork / storage example snippets


// 通过工厂方法创建实例
$class = {$cfg['class']};
$stor = new $class($cfg);

// 通过函数创建

// 函数定义在 wf/web/lib/helper.php
//function wfStorage() {
//    return wfStorage();
//}

$stor = wfStorage();

/**
 * 获取缩略图的URL,一般在模板中使用
 * @param string|ing $path 图片路径或图片附件id
 * @param int $width = 100 为0时按高比例缩放
 * @param int $height = 0 为0时按宽比例缩放
 * @return string
 */
function thumb($path, $width = 100, $height = 0) {
    return wfStorage()->getThumbUrl($path, $width, $height);
}

/**
 * 根据上传文件的Path获取完整URL
 * @param string $path
 * @return string
 */
function storageUrl($path) {
    return wfStorage()->getFullUrl($path);
}

/**
 * 根据上传文件的URL获取Path
 * @param string $url
 * @return string
 */
function storageUrl($url) {
    return wfStorage()->getPathFromUrl($url);
}