PHP code example of yan9 / etocdn
1. Go to this page and download the library: Download yan9/etocdn 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/ */
yan9 / etocdn example snippets angular2html
$image = $request->file('file');
if (!$image->isValid()) {
return '上传失败';
}
$ext = $image->getClientOriginalExtension();
$realPath = $image->getRealPath();
$filename = str_random() . '.' . $ext;
$filename = trim($filename, '/');
$storage = \Illuminate\Support\Facades\Storage::disk('etocdn');
Log::debug('OSS config:', [$filename]);
// 上传文件
$result = $storage->put($filename, file_get_contents($realPath));
if (!$result) return false;
var_dump($storage->url($filename));
// 上传单个url
$filename = 'aaaa.jpg';
$realPath = 'https://cdn.zxlycr.top/37/2021-02-24/37_20210224191240114.jpg';
$result = $storage->put($filename, $realPath);
if (!$result) return false;
var_dump($storage->url($filename));
// 批量上传url
// 如果需要自定义文件名称,请用单个url上传,批量上传不会采用自定义文件名称
// BatchUpload 为批量上传标识
// 上传会保留原始路径,如果以“/”结尾,会将“/”去掉
$realPath = [
'https://cdn.zxlycr.top/37/2021-02-24/37_20210224191240114.jpg',
'https://cdn.zxlycr.top/37/2021-02-25/aaaa.jpg'
];
$result = $storage->put('BatchUpload', serialize($realPath));
if (!$result) return false;
var_dump($storage->url($realPath));