0

I have an install of codeigniter up, running and all is good. Except I want to now offer my users a means of uploading images. The only place I could think to put the folder was in the applications directory (aptly renamed to "app" in my case). Anyway. Since its an MVC I need to run rewrite conditions all over the place. And I believe this to be one of the scenarios.

What I need is to have a condition that works for this subfolder within the app folder

my original rewrite condition is

RewriteCond $1 !^(index\.php|static|robots\.txt)

which works great for those but not for this one case so I need a new condition that works with the above but supports app/upload (is this even possible)?

chris
  • 31,824
  • 49
  • 132
  • 238

2 Answers2

2

Life's a lot easier if you keep your assets outside of application/ (as Robert mentioned).

There are a ton of good asset management Sparks you can pick from to assist with this too - I authored one for my CI projects called sk-asset which provides a lot of view helpers & is structured:

  • /CIAppRoot
    • assets/
      • css/
      • download/
      • img/
      • js/
      • less/
      • swf/
      • upload/
      • xml/
    • application/
    • system/

... htaccess settings can simply bypass CI routing for existing files/dirs/etc:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  # block hidden directories
  RewriteRule "(^|/)\." - [F]

  RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
sekati
  • 535
  • 5
  • 12
  • I think it's important to evaluate what "uploads" mean here. Typically it's (user-generated) content. If you were to make a clean copy of your website / application, would it also contain the uploaded files? If not, then I would seperate them from the assets. – Robert Jun 30 '12 at 18:55
  • Yes, typically `uploads` are assets pushed by the user, whereas `downloads` are provided by the vendor. As per duplicating a "clean copy" of an application, as a git user I simply add assets/uploads/* to my project's .gitignore to insure Im not carrying content between my dev/stage/production environments; so no real need to decouple these asset directories. – sekati Jun 30 '12 at 21:43
1

The upload folder does not have to be in your application directory. In fact, it's better if it's not in it. This way you can separate the application from the content (uploads). You also don't need to rewrite the conditions if you do it this way. This is how my CI directory looks like:

/application
/assets
/uploads
/system     
Robert
  • 1,873
  • 1
  • 17
  • 24