0

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?
stephenthedev
  • 577
  • 1
  • 8
  • 25
  • because it's `/users`, not `users`. Without the `/`. you're dealing with a relative path,starting from wherever this script's current working directory is (e.g. `cwd()`. e.g. if the script is `/foo/bar/script.php`, then `is_dir('users')` will probably be testing `/foo/bar/users`. – Marc B Jun 06 '14 at 17:52
  • I think @fstephen07 may be lost on what `site_url()` does. http://stackoverflow.com/questions/17079711/what-is-the-difference-between-site-url-and-base-url – Jay Blanchard Jun 06 '14 at 17:53
  • A URL is not a file path. – miken32 Jun 06 '14 at 17:55
  • It should be something more along the lines of: $user = $this->session->userdata('username'); mkdir("/users/".$user."/products/".$item_id, 0777, true); – RugerSR9 Jun 06 '14 at 18:07
  • Yes, that fixed it. Thanks. If someone can mark that an answer I will accept it. – stephenthedev Jun 06 '14 at 18:12

1 Answers1

0

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

Nithyanandhan M
  • 1,524
  • 1
  • 16
  • 26