Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] do_upload and the dreaded "The upload path does not appear to be valid"
#1

[eluser]jmbatty[/eluser]
Let me start by saying that I thorougly searched the forum about this error. I tried all the suggestions. with no luck.

here is the story.
I'm starting on codeigniter and decided to migrate portions of my existing site to it, in the learning process. I went through the user_guide, the upload tool example on nettuts (on a different machine.)
I code on mac, with MAMP.

my codeigniter works wonders, and I'm building a forum as the first significant project.
I have the portion of code below that is just killing me.
a view with a form as below
Code:
<form action="http://localhost/codeigniter/index.php/users/avatarupload" method="post" class="loginForm" enctype="multipart/form-data"><br/><input type="file" name="users_avatarFile" value="" id="users_avatarFile"  /><br /><input type="submit" name="submit" value="Upload !"  /></form>

the controller is as follows:

Code:
/***** controller ****/

        function avatarupload() {
            
            $this->load->helper('file');    
                $config['uploadpath']='./images/';
                $config['allowed_types']='gif|jpg|png';
                $config['max_size']='3000';
                $config['max_width']='1024';
                

                                        //testing purposes

                    if ( !write_file($config['uploadpath'].'file34.txt', 'test test test test'))
                    {
                         $mytest= 'Unable to write the file';
                    }
                    else     {    
                         $mytest= 'File written!';
                    }

                $this->load->library('upload');
                $this->upload->initialize($config);
                           // note: $this->load->library('upload', $config); has the same results

                if ( ! $this->upload->do_upload('users_avatarFile')){
                    $this->session->set_flashdata('error', "test write: $mytest<br />path: ".$config['uploadpath'].'
<br/>Could not upload the photo for the following reason:<br/>'.$this->upload->display_errors().' <br />Try again.');
                    
                    redirect('/users/','location');
                }    
                else{
                    $data = array('upload_data' => $this->upload->data());
                    
                    $this->load->view('upload_success', $data);
                }
                

/*** result : **************************

output:

Error :
test write: File written! // and yes, the file is created with the correct content in the correct folder.
path: ./images/
Could not upload the photo for the following reason: // that's the error I get with upload

The upload path does not appear to be valid.  // tadaaa

Try again. // yeah.
**********/

So I can write_file to the folder, but I can't do_upload. "The upload path does not appear to be valid"
I tried many variations of $config['uploadpath'], with FCPATH, base_url, site_url, $_SERVER vars, everything. i tried to initialize($config), or not, same result.
No error in apache.log, or error.log
is_dir() returns that yes, it's a dir.
Folder is 777, and again, write_file just works.

what am I missing ?
#2

[eluser]brianw1975[/eluser]
didja try hard coding the path?

Code:
if ( !write_file('/path/to/mamp/public_html/CI_stuff/images/file34.txt', 'test test test test'))

as for the error logs... did you turn error logging off? never turn it on? not looking at the right log file built into CI?
#3

[eluser]jmbatty[/eluser]
write_file with full path or *any valid form of path naming* just works fine. on the other hand do_upload() does not.
I did not have error logging, great suggestion, thanks.
I turned it on and see this

Code:
DEBUG - 2010-01-06 22:54:09 --&gt; Helper loaded: email_helper
DEBUG - 2010-01-06 22:54:09 --&gt; Controller Class Initialized
DEBUG - 2010-01-06 22:54:09 --&gt; Helper loaded: file_helper
DEBUG - 2010-01-06 22:54:09 --&gt; Upload Class Initialized
DEBUG - 2010-01-06 22:54:09 --&gt; Language file loaded: language/english/upload_lang.php
ERROR - 2010-01-06 22:54:09 --&gt; The upload path does not appear to be valid.

I did a print_r($_REQUEST) and got this
Code:
Array ( [submit] => Upload ! [ci_session] => a:12:{s:10:\"session_id\";s:32:\"fda3812496fd8063fd9e9642c7609ad2\";s:10:\"ip_address\";s:7:\"0.0.0.0\";s:10:\"user_agent\";s:50:\"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en\";s:13:\"last_activity\";s:10:\"1262840049\";s:8:\"username\";s:4:\"user1234\";s:7:\"user_id\";s:1:\"9\";s:8:\"group_id\";s:1:\"0\";s:9:\"logged_in\";s:1:\"1\";s:14:\"user_banStatus\";s:1:\"0\";s:13:\"user_userType\";s:1:\"0\";s:13:\"user_permaBan\";s:1:\"0\";s:15:\"flash:old:error\";s:159:\"File written!

and a print_r($_FILES) gives something like that
Code:
Array ( [users_avatarFile] => Array ( [name] => adSHRMMbr2010.jpg [type] => image/jpeg [tmp_name] => /Applications/MAMP/tmp/php/phpPdHY9c [error] => 0 [size] => 9837 ) )

so i read this as it receives the file, but i am missing why the next step fails, when the apache user can read and write to the $config['uploadpath'] with no problems, the file is not too big, and fits the $config requirements

I'm putting my puzzle face on.
#4

[eluser]jmbatty[/eluser]
another test i made

Code:
if(isset($_FILES['users_avatarFile'])){  
         $file   = read_file($_FILES['users_avatarFile']['tmp_name']);  
         $name   = basename($_FILES['users_avatarFile']['name']);  
          
         write_file('images/'.$name, $file);  
  
         $this->session->set_flashdata('error', 'it worked.');
                redirect('users');              
     }  
   else {
     $this->session->set_flashdata('error', 'again it failed.');
            redirect('users');
     }

works just fine... the file is uploaded into the right folder, but, i would prefer to use the upload class for that purpose...
#5

[eluser]jmbatty[/eluser]
SOLVED !
and it took me a full day to see it

Code:
$config['uploadpath']='./images/'; // that's VERY incorrect


// the correct version should have been
$config['upload_path']='./images/';




Theme © iAndrew 2016 - Forum software by © MyBB