2016-05-13 47 views

回答

1

要上傳您使用下面的代碼圖像或文件到您的控制器

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); 
    } 
} 

Refferecne:Codeigniter Files upload guideline

,如果你想使用Ajax,那麼請不要上傳圖像如何過忘記敲門,然後我會給整個代碼塊。

謝謝!

+0

Codeigniter doc現在位於http://www.codeigniter.com/docs請使用這裏的鏈接而不是ellislab,因爲它們已過時。 – user4419336

+0

謝謝@ wolfgang1983! –

0

您是否試圖將圖像轉換爲字節並將其保存在MYSQL數據庫中? 如果是,請嘗試此代碼

<?php 
$filename = "image.png"; 
$file = fopen($filename, "rb"); 
$contents = fread($file, filesize($filename)); 
fclose($file); 
?>