无法将文件上传到目录

I'm trying to create a folder and then upload a file to the folder. I am receiving the error message:

The upload path does not appear to be valid.

Here is my folder structure:

/System
/Application
/users
     /johndoe
         /products
              /1
              /2

Here is how I am creating the folder:

$productpath = site_url('users/'.$this->session->userdata('username').'/products/'.$item_id);

        mkdir($productpath,777,true); 

So I add the following to my script to try to debug:

var_dump(is_writable(site_url('users')));
var_dump(is_dir(site_url('users')));

Both of those return false. If I echo $productpath:

echo "Here is the product path: ".$productpath;

the upload path is: http://localhost:8888/gameday/users/jackie109/products/49
  • Why is /users not a directory?
  • I assume is_writeable returns false because it cannot be written because it is not a directory
  • Am I linking to my path right? Is site_url the right thing to use here?

Instead of site_url you can use base_url. You should maintain upload files outside the applications directory.

ie., siterootdir/uploads/users

and should not siterootdir/applications/uploads/users