CodeIgniter Forums
Can't upload file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Can't upload file (/showthread.php?tid=55226)



Can't upload file - El Forum - 10-16-2012

[eluser]ArifBD[/eluser]
I am a newbie in CodeIgniter.. i am trying to upload file .. I am following "CodeIgniter User Guide Version 2.1.3: CodeIgniter Home › User Guide Home › File Uploading Class" example for file uploading.. but every time it returns "The upload path does not appear to be valid".... I am using windows 7 operating system and folder permission is set to everyone full permission.... I have also tried from the example of "CodeIgniter from Scratch- Day 9 - File Uploading and Image Manipulation - Nettuts+" and having the same problem... Please need urgent support


Can't upload file - El Forum - 10-16-2012

[eluser]noslen1[/eluser]
Can you post your controller function code ?

Have you created you upload folder in your installation ? CI won't do it for you.

What is your $config['upload_path'] ?




Can't upload file - El Forum - 10-16-2012

[eluser]ArifBD[/eluser]
i have simply use the code from the following page.... and yes i have created a folder name "uploads" in root directory and as it was not working i also created same folder in the application directory.
http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

Controller:
upload.php
Code:
<?php

class Upload extends CI_Controller {

function __construct()
{
  parent::__construct();
  $this->load->helper(array('form', 'url'));
                //$this->document_path= realpath(APPPATH.'../uploads');
}

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

function do_upload()
{
  //$config['upload_path'] = $this->document_path;
                $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 = array('upload_data' => $this->upload->data());
   $this->load->view('upload_form', $error,$data);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());

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



Can't upload file - El Forum - 10-16-2012

[eluser]j0se[/eluser]
Hi.

webserver can write in ./uploads/ ?? Check folder permisions. The folder is in root where are aplication,
system folders???


Can't upload file - El Forum - 10-16-2012

[eluser]ArifBD[/eluser]
"D:\xampp\htdocs\upload\uploads" and also "D:\xampp\htdocs\upload\application\uploads" are the physical folder location, but according to the code it should have been the first one. as it was not working i created the second folder... and yes i have already check the folder permission as i mentioned earlier.


Can't upload file - El Forum - 10-16-2012

[eluser]j0se[/eluser]
Change the name of your folder...
"D:\xampp\htdocs\upload\uploads" to
"D:\xampp\htdocs\uploads\uploads"

config_path is set to "./uploads/" Smile


Can't upload file - El Forum - 10-16-2012

[eluser]ArifBD[/eluser]
it doesn't mater if it is upload or uploads or any xyz at that position .... u can get the full code at
http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html


Can't upload file - El Forum - 10-16-2012

[eluser]noslen1[/eluser]
Is your Upload library autoloaded in your /config/autoload.php file ?
If so, try initialize your config with :
Code:
$this->upload->initialize($config);

instead of :
Code:
$this->load->library('upload', $config);



Can't upload file - El Forum - 10-16-2012

[eluser]j0se[/eluser]
You dont understand me (my english is bad).
I try again, when you configure the settings you say that the folder will be "./uploads/" and in your webroot
( D:\xampp\htdocs\ ) the folder is upload .... I think that you rename the folder o change the config_path.

Not¿?



Can't upload file - El Forum - 10-16-2012

[eluser]noslen1[/eluser]
I think /upload/ (without S) is his root directory where CI is installed, and /uploads/ his upload directory where to put upload files