我是 CI 的新人。 我正在尝试使用 PHP CI 框架上传 webp 图像,任何人都可以给我关于如何上传 .webp 而不是 jpg 的建议吗?
添加 webp MIME 在配置文件中键入:./application/config/mimes.php。 'webp' => 数组('图像/webp'),
并在您的上传配置“allowed_types”中添加“webp”: $config['allowed_types'] = 'gif|jpg|jpeg|png|webp';
.webp 图像调整大小、裁剪、水印 转到https://github.com/shackeelck/webp_ci_3
添加 webp MIME 在配置文件中键入:./application/config/mimes.php。 'webp' => array('image/webp', 'application/octet-stream'),
并在您的上传配置“allowed_types”中添加“webp”:$config['allowed_types'] = 'gif|jpg|jpeg|png|webp';
只需添加 mimes 文件即可
'webp' => array('image/webp', 'application/octet-stream'),
然后是在 codeigniter 中的工作
您可以在CI4中使用这样的文件上传功能:
function upload() {
helper(['form', 'url']);
$database = \Config\Database::connect();
$db = $database->table('TABLE NAME');
$input = $this->validate([
'file' => [
'uploaded[file]',
'mime_in[file,image/jpg,image/jpeg,image/png,image/webp]',
'max_size[file,1024]',
]
]);
if (!$input) {
print_r('Choose a valid file');
} else {
$img = $this->request->getFile('file');
$img->move(WRITEPATH . 'uploads');
$data = [
'name' => $img->getName(),
'type' => $img->getClientMimeType()
];
$save = $db->insert($data);
print_r('File has successfully uploaded');
}
}