Welcome Guest, Not a member yet? Register   Sign In
Please help me this code :()
#1

[eluser]java[/eluser]
I have built a controller that it included one function doUpload, like this:
Code:
class Dangky extends Controller {
    
    function Dangky()
    {
        parent::Controller();
        $this->load->helper('form','url');
        $this->load->model('tintuc_model', 'tintuc');
        $this->load->model('dangky_model', 'dangky');
    }
    
    function index()
    {
                $this->load->view('upload_form', array('error' => ' ' ));
                // and something...
        }
        function doUpload()
    {
            $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());
                $data['content'] = $this->load->view('dangky', $error, true);
            }    
            else
            {
            $contain_array = array('upload_data' => $this->upload->data());
                $this->db->set('file_name', $upload_data['file_name']);
            
                //$this->db->insert('my_database');
                $this->load->view('dangky', array('error' => ' ' ));    
            }
            
    }
and this is my form :
Code:
?=$error;?>
            <?=form_open_multipart('dangki/doUpload'); ?>
          <table cellspacing="0" cellpadding="5" width="100%" border="0">
              <colgroup>
              <col width="30%" />
              <col width="70%" />
              </colgroup>
              <tbody>
                <tr>
                  <td align="right">(<strong>*</strong>) Ảnh chân dung: </td>
  <td align="left">&lt;input id="fileUpPoitrait" type="file" name="fileUpPoitrait" /&gt;</td>
                </tr>
                <tr>
                  <td align="right">(<strong>*</strong>) Ảnh toàn thân: </td>
  <td align="left">&lt;input id="fileUpFullPicture" type="file" name="fileUpFullPicture" /&gt;</td>
                </tr>
                <tr>
                  <td align="right"> Xác nhận của nhà   trường: </td>
  <td align="left">&lt;input id="fileUpCertificate" type="file" name="fileUpCertificate" /&gt;
                  </td>
                </tr>
              </tbody>
          </table>
    &lt;/form&gt;
My form have 3 field wait to upload. i tried to solve my controller to save filename into database and store the image into some folder so that i can load it out to my page later. I dont know how to solve the path of the file name(it's save a full path of the image when upload). Please tell me how to perform it. I have read in user guide of CI but it's too simple and cannot resolve my problems.
#2

[eluser]giaodn[/eluser]
You shouldn't save the full path of uploaded images to DB, only need save the file name instead. I assume your project structure like figure below:

<project_name>
|---&gt;systems
|---&gt;css
|---&gt;uploads

... and the uploads folder is use to store the images after upload.

After upload, you get the file name of uploaded image and save it to DB as the below code:
Code:
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];

// insert $file_name to DB code...

Now you can draw the images to the view like below pseudo-code:
Code:
$file_name = retrive_form_db();
<img src="&lt;?base_url() . 'uploads/' . $file_name ?&gt;"></img>

Hiểu chưa? Nếu chưa hiểu thì tớ giải thích bằng tiếng Việt cho Big Grin
#3

[eluser]java[/eluser]
Oh` tưởng trong này chỉ có mình mình người Việt thôi chứ.Smile
Chắc bạn rành codeigniter lam' nhỉ?
Có thể cho mình nick chat để có gì hỏi được kô?
#4

[eluser]giaodn[/eluser]
[quote author="java" date="1182522212"]Oh` tưởng trong này chỉ có mình mình người Việt thôi chứ.Smile
Chắc bạn rành codeigniter lam' nhỉ?
Có thể cho mình nick chat để có gì hỏi được kô?[/quote]
Chẳng biết có thể coi là rành không nữa, tớ thì tớ là dân JAVA, yêu thích JAVA, cũng chẳng được học PHP, chẳng qua là chuyển công việc có nhu cầu làm PHP nên làm đại, quen với CI được ngót nghét 2 tháng nay. Được cái tớ có chút ít kinh nghiệm lập trình nên làm quen với nó chẳng là vấn đề. Nói có vẻ ngông nghênh thế thôi chứ thực ra là đang chờ feeback từ khách hàng, rảnh rỗi quá lên đây xem có gì hay thì nhìn thấy Vietnamese code Big Grin lên vào xàm xàm tí cho vui thui, tính tớ vốn hay đùa mà Tongue

PS: Yahoo mình là giao_dn, rất vui khi làm quen với bạn, mình ở HCM
#5

[eluser]Unknown[/eluser]
Ôi, chết cười mất. Hóa ra ở đây lắm dân mình ghê. Add nick trao đổi kinh nghiệm nhé mấy bồ.
#6

[eluser]Unknown[/eluser]
hix minh moi tim hieu duoc 1 tuan !
hai ban viet nam co ma phan login/register khong cho send cho minh tham khao voi !
thanks all !
sorry vi khong co vietkey !
#7

[eluser]Unknown[/eluser]
Hay quá tui đang làm một phần mềm bằng cái này. Nên rất cần tham khảo ý kiến chỉ giáo của các bạn. Hiện giờ mình cũng mắc chỗ này. Làm việc giữa upload - Data - del file -... Nick yahoo: findprice có gì liên lạc nhé.




Theme © iAndrew 2016 - Forum software by © MyBB