wordpress插件大全?开发WordPress插件并将其发布到正式插件库的完整指南小白也可以
开发和发布自己的wordpress插件到官方插件库完全指南wordpress是一款很流行的开源博客程序,全世界有很多网站都在使用wordpress,程序员们也喜欢拿来做自己的技术博客,对于自己不满意的
顺晟科技
2022-11-02 14:02:17
140
gargron/fileupload插件地址:https://packagist.org/package...
composer require gargron/fileupload
//设置上传文件格式
$magicFile = Yii::getAlias(FileHelper::$mimeMagicFile);
$mimeTypes = require($magicFile);
$allowExt = ['png', 'jpg'];
foreach ($allowExt as $ext) {
if (isset($mimeTypes[$ext])) {
$allowMimes[] = $mimeTypes[$ext];
}
}
//验证(最大文件大小2MB,只有两个允许的mime类型)
$validator = new \FileUpload\Validator\Simple('2M', $allowMimes);
$savePath = 'upload/';
//判断是否存在上传目录,不存在创建目录
if (!is_dir($savePath)) {
FileHelper::createDirectory($savePath);
}
// 上传文件
$pathresolver = new \FileUpload\PathResolver\Simple($savePath);
// The machine's filesystem
$filesystem = new \FileUpload\FileSystem\Simple();
// files为上传控件的name名
$fileupload = new \FileUpload\FileUpload($_FILES['files'], $_SERVER);
// Adding it all together. Note that you can use multiple validators or none at all
$fileupload->setPathResolver($pathresolver);
$fileupload->setFileSystem($filesystem);
$fileupload->addValidator($validator);
// Doing the deed
list($files, $headers) = $fileupload->processAll();
foreach($files as $file){
//Remeber to check if the upload was completed
if ($file->completed) {
echo $file->getRealPath();
// Call any method on an SplFileInfo instance
var_dump($file->isFile());
}
}
根据如上代码可以实现文件上传
26
2023-02
26
2023-02
26
2023-02
02
2022-11
02
2022-11
02
2022-11