Files above the root - how does this work?

Thread Solved

Join Date: Aug 2009
Posts: 40
Reputation: slyme is an unknown quantity at this point 
Solved Threads: 3
slyme slyme is offline Offline
Light Poster

Files above the root - how does this work?

 
0
  #1
Aug 25th, 2009
Sorry to all if this is in the wrong forum, I'll move it if someone tells me where it should go.

I saw another poster discussing some files stored above the root ... well here's what was posted:

"I have a script which generates invoices as PDF files and stores above just above www level (so they cannot be access directly via a URL)."

How does this work (I would like to use this)? If the files cannot be accessed via a URL, how are they accessed?

Thanks,

Simon.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,973
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Files above the root - how does this work?

 
0
  #2
Aug 25th, 2009
>Sorry to all if this is in the wrong forum
If your script is written in PHP, and your question is related to PHP/your script, then I would say that it's in the correct forum.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 9
Reputation: kokoro90 is an unknown quantity at this point 
Solved Threads: 6
kokoro90 kokoro90 is offline Offline
Newbie Poster

Re: Files above the root - how does this work?

 
0
  #3
Aug 25th, 2009
You can reference files outside the DocumentRoot in your PHP scripts. You can use either relative or absolute path names, since PHP can "see" the whole file system.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 40
Reputation: slyme is an unknown quantity at this point 
Solved Threads: 3
slyme slyme is offline Offline
Light Poster

Re: Files above the root - how does this work?

 
0
  #4
Aug 25th, 2009
Yep, it's a PHP thingie then!

Right, so I store the files outside of the root. Users log on to the site and get the appropriate session details set. Then they browse to a page full of links to various files, PDFs and MP3s. Some files are public and everyone gets that list. Some files are private and only logged users see that list.

How should I form the URL to link to the private files and what's to stop a user returning to a file after they have logged off?

Thanks,

Simon.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 26
Reputation: farhan386 is an unknown quantity at this point 
Solved Threads: 3
farhan386's Avatar
farhan386 farhan386 is offline Offline
Light Poster

Re: Files above the root - how does this work?

 
0
  #5
Aug 26th, 2009
you should put the public and private files into separated directory.
Create a script using directory functions available in PHP such as scandir() to list the directory content. You may protect this file using session so that only logged user may access it.
I'm spammer...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 40
Reputation: slyme is an unknown quantity at this point 
Solved Threads: 3
slyme slyme is offline Offline
Light Poster

Re: Files above the root - how does this work?

 
0
  #6
Aug 27th, 2009
Ah ... now that's the bit I don't get ... how do I protect a file or a directory using PHP (general pointers ... not asking for it to be done for me!)?

I have a log in routine, the relevent session is set and that's fine, I can do anything I like inside a page using PHP to list information acoording to logged status.

So, say I list a load of links to a some mp3 files and some of these mp3s are only listed for logged on users ... what's to stop someone simply putting the URL for the mp3 file itself in? They would still get the file even if they were not logged in.

My code has to work on Windows IIS and Apache. I believe that I could accomplish this on a Linux machine with .htaccess but I don't have that luxury.

As a point of interest, will .htaccess work on sites hosted on my mac?

thanks for your help,

Simon.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,398
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Files above the root - how does this work?

 
0
  #7
Aug 27th, 2009
using php the user neve sees the url of the file
and without a logged in session nothing
  1. <?php /* download.php */
  2. if(!session_id) { die ('only registered users'); } // better session validation than that but its a thought example
  3. $hiddenfile="../absolutepath/$filename";
  4. header('Content-type: file/mp3'); // I dunno and I'm too lazy to look up (audio/mpeg)?
  5. header('Content-Disposition: attachment; filename="$filename"');
  6. readfile("$hiddenfile");
  7. ?>
very poor code unchecked dont think it works its a concept example
Last edited by almostbob; Aug 27th, 2009 at 8:32 pm.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,398
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 170
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Files above the root - how does this work?

 
1
  #8
Aug 28th, 2009
  1. <a href='download.php?$filename=whilemyguitar.mp3'>the beatles-while my guitar gently weeps</a>
  1. <?php /* download.php */
  2. if(!session_id) { $hiddenfile="../absolutepath/polkamusic.mp3"; } // evil laugh
  3. else $hiddenfile="../absolutepath/$filename";
  4. header('Content-type: file/mp3'); // I dunno and I'm too lazy to look up (audio/mpeg)?
  5. header('Content-Disposition: attachment; filename="$filename"');
  6. readfile("$hiddenfile");
  7. ?>
!logged_in users get polka music for every mp3 they download
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 40
Reputation: slyme is an unknown quantity at this point 
Solved Threads: 3
slyme slyme is offline Offline
Light Poster

Re: Files above the root - how does this work?

 
0
  #9
Aug 28th, 2009
Almostbob you are a star, thank you. The penny has finally dropped. This has vexed me for some years now and I finally get it thanks to your replies. Now, if someone could explain what the second number in a musical time signature means then I would be walking on air!

I love the idea of serving up polka music to hackers!

thanks,

Simon.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 332 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC