2013-08-27 229 views
-1

我是新codeigniter ..請幫助我上傳codeigniter.first圖像我需要創建一個子文件夾「codeigniter/userimage /」與用戶ID作爲文件夾名稱。我做that.this是我的控制器功能圖像上傳到codeigniter子文件夾

function update(){ 
    $uppath="/var/www/html/codeigniter/userimage/"; 
    $sess_id= $this->session->userdata('userid'); 
    $folder=$uppath.$sess_id; 
    if(!is_dir($folder)) 
    mkdir ($folder,777); 

    if($x>0){ 
     $config['upload_path']='./userimage/'.$folder.'/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
     $config['max_size'] = '9000'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '1000'; 
     echo 'haii'; 
     $this->load->library('upload'); 
     $this->upload->initialize($config); 
     echo 'heloooo'; 
     if (!$this->upload->do_upload('picfile')) { 
      print_r($this->upload->display_error());die; 
     } 
     else { 
      $image=$this->upload->do_upload('picfile'); 
      // echo 'uploaded'; 
      echo $image; 
     } 
    } 
} 

我打電話我從視圖「profileinfo」模型「家」裏寫的方法更新。

我的看法是profileinfo:

`<?php 
    $fn=''; 
$ln=''; 
$un=''; 
$em=''; 
$b=''; 
$gr=''; 
foreach ($query as $row){ 
$fn=$row->firstname; 
$ln=$row->lastname; 
    $un=$row->username; 
    $em=$row->email; 
$b=$row->bday; 
$gr=$row->gender; 
} 
?> 
<html> 
<head></head> 
<body> 
    <h1><u>My Profile Details</u></h1> 
    <br><br><div id="viewdiv" align="center"> 

      <div align="right" style="font-weight: bold;font-size: 20px;"> 
     <a href="home">Back</a></div> 
     <?php echo form_open_multipart('home/update');?> 
<br> 
<table border="0" align="center"> 
    <tr class='spacerow'> 
     <td> 
      <h2> Name:</h2> 
     </td> 
     <td><?php echo"<input type='text' name='first' value='$fn'>";?> 
     <?php echo"<input type='text' name='last' value='$ln'>";?></td> 
    </tr> 
    <tr class='spacerow'> 
     <td> 
      <h2> User Name:</h2> 
     </td> 
     <td> 
      <?php echo"<input type='text' name='uname' value='$un'>";?> 
     </td> 
    </tr> 
    <tr class='spacerow'> 
     <td> 
      <h2> Date of birth:</h2> 
     </td> 
     <td> 
      <?php echo"<input type='text' name='dobb' id='datepicker' value='$b'>";?> 
     </td> 
    </tr> 
    <tr class='spacerow'> 
     <td> 
      <h2> Gender: </h2> 
     </td> 
     <?php 
     if($gr=="male"){ 
      ?> 
     <td> 
      <?php echo"<h3>Male:<input type='radio' name='gen' value='male' checked>";?> 
      <?php echo"Female:<input type='radio' name='gen' value='female' ></h3>";?> 
     </td> 
     <?php 
        } 
        else{ 
     ?> 
     <td> 
      <?php echo"<h3>Male:<input type='radio' name='gen' value='male'>";?> 
      <?php echo"Female:<input type='radio' name='gen' value='female' checked></h3>";?> 
     </td> 
     <?php 
        } 
        ?> 
    </tr> 

    <tr class='spacerow'> 
     <td> 
      <h2> Email:</h2> 
     </td> 
     <td> 
      <?php echo"<input type='text' name='mail' value='$em'>";?> 
     </td> 
    </tr> 
    <tr class='spacerow'> 
     <td> 
      <h2> Profile Picture:</h2> 
</td> 
<td> 
    <input type="file" name="picfile"> 
    <p>if you want to change your profile picture,browse here..</p> 


</td> 
    </tr> 


    <tr> 
    <td><br> 
     <center> <input type="submit" name="update" value="update"></center> 

    </td> 
    <td> 

    </td> 
    </tr> 


</table> 



    </div>  
</body> 

` 子文件夾「$文件夾」在裏面userimage創造,我想存儲上傳的圖片成子folder.my問題是圖像不上傳。你可以看到我在加載上傳庫之前和之後放置了兩個echo語句。但我發現只有輸出「haii」 ..我不明白什麼是problem..please人幫助我..感謝任何想法..

+0

那麼到底是什麼由do_upload函數返回?什麼是錯誤信息? – Technoh

+1

您需要使用chmod()賦予文件夾的777權限。 – Prasannjit

+0

@Technoh:沒有錯誤消息顯示..當我點擊按鈕後瀏覽圖像的URL顯示頁面正在移動到控制器中指定的方法..但圖像不上傳...這是我的問題.. – user007

回答

0

首先使用:

$uppath='./codeigniter/userimage/'; 

什麼是您的文件字段名稱?如果它不userfile然後提供字段名這樣的:

if (! $this->upload->do_upload('field_name')) 

而且最後打印這樣的錯誤調試:

print_r($this->upload->display_error());die; 

編輯:

function update(){ 
    $uppath="/var/www/html/codeigniter/userimage/"; 
    $sess_id= $this->session->userdata('userid'); 
    $folder=$uppath.$sess_id; 
    if(!is_dir($folder)) 
    mkdir ($folder,777); 

    if($x>0){ 
     $config['upload_path']  = './userimage/'.$sess_id.'/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
     $config['max_size']   = '9000'; 
     $config['max_width']  = '1024'; 
     $config['max_height']  = '1000'; 
     echo 'haii'; 
     $this->load->library('upload', $config); 
     //$this->upload->initialize($config); 
     echo 'heloooo'; 
     if (!$this->upload->do_upload('picfile')) { 
      print_r($this->upload->display_errors());die; 
     } 
     else { 
      $image=$this->upload->do_upload('picfile'); 
      // echo 'uploaded'; 
      echo $image; 
     } 
    } 
} 
+0

當我給你$ uppath像你說的..它顯示錯誤,「沒有這樣的目錄被發現」..和我的子文件夾創建時,我給完整的路徑。 。我的問題是瀏覽的圖像沒有上傳.. – user007

+0

目錄'codeigniter',它是你的項目的'根目錄'嗎?如果'是然後'寫'$ uppath ='。/ userimage /';' –

+0

海先生..感謝您的幫助..我張貼上面編輯的代碼如您所說..但再次它的不工作..你會請再次查看編輯後的問題? PLZ? – user007