Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Downloading Directory Files Restriction
Old 09-22-2009, 05:11 AM Downloading Directory Files Restriction
Experienced Talker

Posts: 34
Trades: 0
Hi,

Is there a way to restrict file downloads from a directory (residing in root hierarchy ) to login users only. Meaning if a user get to know the url of a file, it can be downloaded without requiring to login to the system.

Any solution to it?

Thanks
autumn is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-22-2009, 10:18 AM Re: Downloading Directory Files Restriction
Average Talker

Posts: 16
Location: Europe
Trades: 0
The first solution that came in my mind is to password protect this directory so the content is available only to the users that know that password. You should have this option in your control panel. Do you have CPanel?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
seomarketer is offline
Reply With Quote
View Public Profile Visit seomarketer's homepage!
 
Old 09-22-2009, 02:12 PM Re: Downloading Directory Files Restriction
Experienced Talker

Posts: 34
Trades: 0
Yes and as the directory is accessed by number of user accounts not just a single one. Directory is not within the website structure so website password doesnt imply on that, but during download one can get to know the address of that directory.

1) Is there a way to put .htaccess restriction for many accounts ?
2) And to hide status bar url address visibility during download of file ?


Thanks
autumn is offline
Reply With Quote
View Public Profile
 
Old 09-22-2009, 04:04 PM Re: Downloading Directory Files Restriction
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You could have a database refer to all your downloadable contents, and have php serve the content, only giving away an ID instead of the url. So the url would be like download.php?fileID=12345

I'm not sure I remeber exactly how to do this but at least you need to call the header() function and tell the browser that it is to be interpreted as an image, then I believe you can use the function readfile(). So your download.php file should look something like this.
PHP Code:
<?php

$id 
$_GET['fileID'];

// validate the id

// connect to database and retrieve actual url to file
$file "the url to your file, retreived from the database";

// Example of a pdf document
// See the manual for all the different data types
header('Content-type: application/pdf');
readfile($file);

?>
And you would call it as in

<a href="download.php?fileID=12345">Download PDF</a>

EDIT: I meant for hiding the files true urls. Can't help you with the .htaccess :P
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.

Last edited by lizciz; 09-22-2009 at 04:07 PM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 09-23-2009, 05:00 AM Re: Downloading Directory Files Restriction
Experienced Talker

Posts: 34
Trades: 0
Hey Lizciz,

Thanks for replying and forwarding a solution, it sure provided the idea to solve my problem.

Cheers and Regards.
autumn is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Downloading Directory Files Restriction
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53417 seconds with 12 queries