Thread subject: Explore Your Brain :: [SOLVE] codeigniter: uploading file

Posted by letsmove on 09-04-2012 06:37
#1

masta masta, mohon bantuannya ya. saya sedang belajar upload file menggunakan codeigniter

error yang saya dapatkan adalah seperti ini:

"The upload path does not appear to be valid."

dan inilah script asli yang ada di dokumentasi codeigniter

letak: view/upload_form.php

Code
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />

</form>

</body>
</html>





Letak : view/upload_success.php

Code
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<h3>Your file was successfully uploaded!</h3>

<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>

<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>

</body>
</html>




dan ini controllernya: controller/upload.php

Code
<?php

class Upload extends CI_Controller {

   function __construct()
   {
      parent::__construct();
      $this->load->helper(array('form', 'url'));
   }

   function index()
   {
      $this->load->view('upload/upload_form', array('error' => ' ' ));
   }

   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/upload_form', $error);
      }
      else
      {
         $data = array('upload_data' => $this->upload->data());

         $this->load->view('upload/upload_success', $data);
      }
   }
}
?>





dan untuk struktur kode yang saya buat adalah seperti berikut

+application
+css
+image
+system
+uploads

:?plz? :hlp

Edited by letsmove on 11-04-2012 01:44

Posted by EVA-00 on 09-04-2012 09:19
#2

Hak akses direktori /upload & sub foldernya udah di set 777 blm?

Posted by letsmove on 10-04-2012 23:14
#3

udah tapi belum bisa juga masih error.

Code
chmod -vR 777 docclassifier/upload





oh iya lupa kasih info os nya. saya menggunakan ubuntu 10.10

Edited by letsmove on 10-04-2012 23:15

Posted by letsmove on 11-04-2012 01:43
#4

yes, udah ketemu masalahnya masta, ternyata pas dibagian ini:

Code
$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);




perlu ditambahkan code seperti ini

Code
$this->upload->initialize($config);




jadinya :

Code
<?php

class Upload extends CI_Controller {

   function __construct()
   {
      parent::__construct();
      $this->load->helper(array('form', 'url'));
   }

   function index()
   {
      $this->load->view('upload/upload_form', array('error' => ' ' ));
   }

   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);
                $this->upload->initialize($config);
                                           
               
               
      if ( ! $this->upload->do_upload())
      {
                        $cek = var_dump(is_dir('./uploads'));
         $error = array('error' => $this->upload->display_errors());

         $this->load->view('upload/upload_form', $error,$cek);
      }
      else
      {
         $data = array('upload_data' => $this->upload->data());

         $this->load->view('upload/upload_success', $data);
      }
               
   }
}
?>





thanks to codeigniter forum.