2

I currently am blocking all access to one directory in on my server using .htacces

deny from all

I use php for all my coding, except at one point I use javascript to play mp3s from my secured directory. But this is blocked by the .htaccess

Is there anyway to allow the javascript access to the directory but still block people from typing in the url and gaining access to the files.

Sorry, I'm new to .htaccess and can't figure it out.

Thanks.

Olokoo
  • 1,114
  • 3
  • 19
  • 34

3 Answers3

4

No, JavaScript is client side; thus, if it can access the files, the client can too.

Considering moving the files into a non-public directory, perhaps even outside of webroot, and then reading them & sending them to the client using a script. This can be easily accomplished with PHP.

djdy
  • 6,779
  • 6
  • 38
  • 62
1

Nope, not that I'm aware of. Why don't you just move the music into another directory that has an index so all the music files aren't listed?

David Harris
  • 2,697
  • 15
  • 27
  • Yeah, that is the way that I used to have it set up, the problem was I don't want people to be able to get to the files from a url. – Olokoo Dec 25 '12 at 03:48
0

I ended up using this code to allow access to mp3s and oggs and nothing else. It's not optimal but it works.

deny from all

<FilesMatch ".(ogg|mp3)$">
Order Allow,Deny
allow from all
</FilesMatch>

Thanks for the answers.

Olokoo
  • 1,114
  • 3
  • 19
  • 34
  • Using this code will not prevent the clients from accessing the files directly. – djdy Dec 25 '12 at 05:19
  • Your right, that's why I am going to accept your answer as the correct one for my particular question. This is merely just a work around. – Olokoo Dec 25 '12 at 17:07