2012-12-29 70 views
-3

我寫了下面的代碼,但它不工作。如何使用codeigniter上傳文件?

$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); 
     $this->upload->do_upload('product_image'); 

HTML表單:

<body> 
    <form method="post" action="localhost/codeigniter/index.php/product/insert" enctype="multipart/form-data"> 
    <label>Product Name :</label> <input type="text" name="product_name"/><br/> 
    <label>Product Image :</label> <input type="file" name="product_image"/><br/> 
    <input type="submit" name="submit" value="Submit"/> 
    <?php echo validation_errors(); ?> 
    </form> 
</body> 
+3

什麼錯誤你得到?向我們展示您的html表單 – GBD

+0

請提供更多信息,whay不工作?你得到什麼錯誤? – RezaSh

+0

我沒有收到任何錯誤。文件沒有上傳。 –

回答

3

你寫錯了HTML表單

1)你給;在表單行爲屬性後的表單中。

2)您已經在表單標籤前關閉了body標籤。

3)使用絕對路徑。

Repalce表單與此代碼:

<body> 
    <form method="post" action="<?php echo base_url();?>product/insert" enctype="multipart/form-data"> 
    <label>Product Name :</label> <input type="text" name="product_name"/><br/> 
    <label>Product Image :</label> <input type="file" name="product_image"/><br/> 
    <input type="submit" name="submit" value="Submit"/> 
    <?php echo validation_errors(); ?> 
    </form> 
</body> 
+0

我應該在哪裏放置'uploads'文件夾? –

+0

@DigmaChauhan在應用程序和系統文件夾爲 – sandip

+0

文件的同一級別未上載到「上傳」文件夾中。我也沒有得到任何錯誤。 –