Welcome Guest, Not a member yet? Register   Sign In
"The upload path does not appear to be valid"
#1

[eluser]ellipsis[/eluser]
Hello. I'm trying to create a simple upload form by following the example in the user guide and I keep getting that horrid error. I've tried countless variations on the path ./uploads/files/ and nothing has worked so far. Just to not waste anybody's time here I'm going to answer some of the usual questions. Yes "file_uploads" is set to "on" in php.ini. I'm running XAMPP on Vista x64.
My directory structure is as follows
Quote:C:
|
|-\xampp
| |
|--\htdocs
| |
|---\site
| |
|----\backend
|----\css
|----\frontend
|----\img
|----\js
|----\system
|----\uploads
| |
|-----\files
|----\user_guide

My .htaccess contains the following lines, although it is my understanding that php ignores it so it might actually be of no relevance to the problem
Quote:RewriteEngine on
RewriteCond $1 !^(index\.php|admin\.php|favicon\.ico|css|js|img|uploads|user_guide|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]


Code:
//controllers/files.php
<?php

class Files extends Controller {

    function Files()
    {
        parent::Controller();    
        
        //$this->load->library('session');
        $this->load->model('Content_model', "", TRUE);
        $this->load->library('upload');
        $this->load->library('form_validation');
    }
        
        function do_upload()
    {
        //$upath=.$this->session->'./uploads/files/'.userdata('uid').'/';    
        $config['upload_path'] = './uploads/files/';
        $config['allowed_types'] = 'exe|zip|rar|jar|jpg|jpeg|png|gif';
        $config['max_size']    = '0';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
        $data['page_title']="Files";
        
        $logdata['username']=$this->session->userdata('username');
        $logdata['logged_in']=$this->session->userdata('logged_in');
        
        if($logdata['logged_in']==TRUE)
        {
            $this->load->vars($logdata);
            $data['form_content']=$this->load->view('loggedintop', "", TRUE);        
            //$db['query']=$this->Content_model->add_files($filefields);
        }
        else
        {
            $data['form_content']=$this->load->view('login_form', "", TRUE);
            $db['query']=NULL;
        }
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $data['page_content']=$this->load->view('files', $error, true);
            
            $this->load->vars($data);
            $this->load->view('header');
            $this->load->view('content');
            $this->load->view('footer');
        }    
        else
        {
            $error['upload_data']= $this->upload->data();
            
            $data['page_content']=$this->load->view('files', $error, true);
            
            $this->load->vars($data);
            $this->load->view('header');
            $this->load->view('content');
            $this->load->view('footer');
        }
    }    
        
    function index()
    {
        $data['page_title']="Files";
        
        $logdata['username']=$this->session->userdata('username');
        $logdata['logged_in']=$this->session->userdata('logged_in');
        
        if($logdata['logged_in']==TRUE)
        {
            $this->load->vars($logdata);
            $data['form_content']=$this->load->view('loggedintop', "", TRUE);        
            //$db['query']=$this->Content_model->add_files($filefields);
        }
        else
        {
            $data['form_content']=$this->load->view('login_form', "", TRUE);
            $db['query']=NULL;
        }
            $error['error']="do your thing...";
            $data['page_content']=$this->load->view('files', $error, true);
            
            $this->load->vars($data);
            $this->load->view('header');
            $this->load->view('content');
            $this->load->view('footer');
    }
    

}

/* End of file files.php */
/* Location: ./frontend/controllers/files.php */
?>


Code:
//views/files.php
<?php    echo $error;
    echo form_open_multipart('files/do_upload');
    echo '<input type="file" name="userfile" size="20" />
        <input type="submit" value="upload" />
        </form>';
?>

If anyone can spot the problem or point me in the right direction, I'd be really grateful.
#2

[eluser]TheFuzzy0ne[/eluser]
Are you getting any errors? Is the uploads directory writeable?

You should pass the error into the view via your $data array, so:
Code:
$data['error']="some_error";
$data['page_content']=$this->load->view('files', $data, true);

But you're code is a little out of whack, since you're loading vars after the views and not before.

I'd suggest a bit of a restructure. Some of that logic can be handled from within your views. For example, you could have a view named "login_form.php", which would contain some simple logic to display the form if the user is not logged in, and display something else if the user is. In your case, you should ideally only need to make a single call to $this->load->vars(), and only load a single view from your controller. You're main view can include the header, navigation menu, footer etc...

Hope this helps. If not, I can probably give you an example.
#3

[eluser]ellipsis[/eluser]
The error I'm getting is the topic's name itself "The upload path does not appear to be valid". The $error that you see in index() is put there only temporarily because seeing that little warning that the variable error wasn't found was getting annoying, but that is not the problem here. When calling do_upload() by clicking the upload button, the page does return with an error so it's being passed fine, but the problem is WHY am I getting "The upload path does not appear to be valid" ? And yes, the directory is writable.
#4

[eluser]TheFuzzy0ne[/eluser]
I'd try using some straight PHP to create a file in that directory. That way you can be sure you've definitely got the right path.
#5

[eluser]ellipsis[/eluser]
Another user in a similar thread on the CI forums suggested to vardump the path to see if the server can see it.
Code:
var_dump(is_dir('./uploads/files/');
and I get bool(true), so I guess the path is fine...
I also tried the code that I eventually want to use to create a subfolder for each user, using their id number.
Code:
$upath='./uploads/files/'.$this->session->userdata('uid').'/';
    var_dump(is_dir($upath));
this also returned bool(true).

Any ideas?... any? I'd try making the upload form, but frankly I don't even know how in CI.
#6

[eluser]ellipsis[/eluser]
shameless bump...
#7

[eluser]jedd[/eluser]
You could use the [url="http://net.tutsplus.com/videos/screencasts/easy-development-with-codeigniter/"]Net Tuts File Upload[/url] code as your base.

I rattled up a copy of their code and got it working in a few minutes (just needed to fix up their paths and my perms).

If you look at your web server logs you should be able to see where you are failing to have write permissions for the uploaded file - this will prove out that you are actually writing to the place that you believe you are writing to.

What permissions do you have on your upload directory at the moment anyway?
#8

[eluser]ellipsis[/eluser]
Actually I just read your recommendation of that tut in another thread and was watching it to see what I did wrong and nobody, including me, noticed that I loaded the upload library in Files() and then loaded it again in do_upload() with the $config array appended to it and by checking the logs I noticed these interesting lines:
Quote:DEBUG - 2009-06-28 00:48:31 --> Upload Class Initialized
DEBUG - 2009-06-28 00:48:31 --> Upload class already loaded. Second attempt ignored.

as soon as I removed the line from Files(), everything was just fine :lol: and now I can use the code I wanted to use in the first place Big Grin

Code:
$upath='uploads/files/'.$this->session->userdata('uid').'/';    
$config['upload_path'] = $upath;

That video was a life saver. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB