[英]Codeigniter code required for image upload in database
我需要完整的代碼,我可以在數據庫中上傳完整的圖像大小(不僅是圖像路徑,而且是整個圖像大小)。 先感謝您
要上傳圖像或文件,您使用以下代碼到您的控制器
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
參考:Codeigniter 文件上傳指南
如果您想使用 Ajax 上傳圖像,請不要忘記敲門,然后我將提供完整的代碼塊。
謝謝!
您是否嘗試將圖像轉換為字節並將其保存在 MYSQL 數據庫中? 如果是,那么試試這個代碼
<?php
$filename = "image.png";
$file = fopen($filename, "rb");
$contents = fread($file, filesize($filename));
fclose($file);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.