欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用CodeIgniter的類庫(kù)做圖片上傳

 更新時(shí)間:2014年06月12日 15:20:34   投稿:shichen2014  
CodeIgniter的文件上傳類允許文件被上傳。您可以設(shè)置指定上傳某類型的文件及指定大小的文件。這篇文章主要介紹了使用CodeIgniter的類庫(kù)做圖片上傳,需要的朋友可以參考下

CodeIgniter的文件上傳類允許文件被上傳。您可以設(shè)置指定上傳某類型的文件及指定大小的文件。

上傳文件普遍的過(guò)程:

一個(gè)上傳文件用的表單,允許用戶選擇一個(gè)文件并上傳它。
當(dāng)這個(gè)表單被提交,該文件被上傳到指定的目錄。
同時(shí),該文件將被驗(yàn)證是否符合您設(shè)定的要求。
一旦文件上傳成功,還要返回一個(gè)上傳成功的確認(rèn)窗口。

下面是表單:

復(fù)制代碼 代碼如下:
<form method="post" action="<?=base_url()?>admin/img_upload/" enctype="multipart/form-data" />
 <div style="margin:0 0 0.5em 0em;">
  <input type="file" name="userfile" size="20" class="button" />
  <input type="submit" value=" 上傳 " class="button" />
 </div>
</form>

然后是下面是上傳類:

復(fù)制代碼 代碼如下:
public function img_upload()
{
 $this->load->helper('url');

 $config['upload_path'] = './images/'.date('Ym', time()).'/';
 $config['allowed_types'] = 'gif|jpg|png';
 $config['file_name'] = date('Y_m_d', time()).'_'.sprintf('%02d', rand(0,99));
 $config['max_size'] = '500';
 $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());
   }
 else
   {
     $data = array('upload_data' => $this->upload->data());
   }
}


需要用到的幾個(gè)函數(shù)

$this->upload->do_upload():根據(jù)你的偏好配置參數(shù)執(zhí)行操作。注意:默認(rèn)情況下上傳的文件來(lái)自于提交表單里名為userfile的文件域,并且該表單必須是 "multipart"類型。
$this->upload->display_errors():如果do_upload()返回失敗,顯示錯(cuò)誤信息。此函數(shù)不會(huì)自動(dòng)輸出,而是返回?cái)?shù)據(jù),所以你可以按你的要求安排。
$this->upload->data():這是一個(gè)輔助函數(shù),它返回你上傳文件的所有相關(guān)信息的數(shù)組。

相關(guān)文章

最新評(píng)論