| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | How do the download scripts work? Hey I cant figure out something how does a non database [flat file] download script work? i know how you will be able to upload a file to a directory..but now how do you restrict only registered people to download that file! if it was a php file..then in the php file..you could use sessions..but if a user uploads abc.zip under "uploads" its basically available to anyone who goes to domain.com/uploads/abc.zip ..my question is..how do you restrict only registered users to be able to download that! Thanks
__________________ |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: USA
Posts: 497
![]() ![]() | i wouldn't show the user where the file was uploaded so the URL would be something like http://www.site.com/file.php?id=4824jdf82894hc828fh28 or something. And have the file renamed from abc.zip to 28427427abc.zip just to make things safer. Also, I believe there is a way to have a file downloaded instead of it being ran on the server, for example an image file. I'll tell you when I'v found something. |
| |
| | THREAD STARTER #3 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | well its for Vbulletin.i couldnt find a Mod for it..and the files are too big to be uploaded through the Vbulletin Attachment system [it saves it in the database]
__________________ |
| |
| | #4 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I am not familiar with Vbulletin's attachment system but what makes you say it does not use a database? Vbulletin is very database heavy and I would think it definitely uses a database for the download. If however you are making 1 and 100% do not want people to download files that are not allowed too you could do something like the following:- Upload files to a non www based folder. ????: NamePros.com http://www.namepros.com/programming/311178-how-do-the-download-scripts-work.html If you want the files to look like they are downloading from a particular folder create a folder and put a htaccess file in it using a redirect rule (more with that in a sec) Put a php script in the file that checks if the person is a registered user (very easy to do, just use Vbulletin's own global php file) In the check to see if the user is registered and if they are check the file exists in your download folder. Check extension of the file and output correct headers. Use file_get_contents or a similar method to echo the content out to the client. Now regarding the htaccess file. If for example you want your downloads to look like:- http://www.mydomain.com/download/file.ext make a folder in your root directory called download. Create a .htaccess file that rewrites the address to http://www.mydomain.com/download/scr...?file=file.ext (in the php file ensure of course that only allowed chars are in the file name to ensure that people cannot traverse your server and download anything they want). |
| |
| | #5 (permalink) |
| If only you knew... Join Date: Oct 2005 Location: Inside your head...
Posts: 998
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | As Peter suggested, move downloads to a directory outside root (non browser accessable directly). PHP Code: ), and requires cookies enabled (I haven't looked into sessions for vBulletin). But the login cookies for it are those (bbuserid & bbpassword). You could also check into comparing those values with the database of users, incase browser doesn't have cookies turned on (ie: sessions being used). Something to consider, also, is the file formats, and how they may be treated (ie: normally displayed like text files, versus forced downloads for textfiles). For more info on that, see PHP.net's header() manual.
__________________ --- The greatest truths ever told, and the greatest lies ever told, all consist of exactly the same three words: "I LOVE YOU" --- The best say little, only say what is important.....then they shut up and sit down. |
| |
| | #6 (permalink) |
| Senior Member Join Date: Nov 2005 Location: on a oil rig just off Ireland
Posts: 1,408
![]() ![]() ![]() ![]() ![]() | Look into headers on the php manual. http://uk2.php.net/manual/en/function.header.php Specifically PHP Code:
__________________ You design in photoshop, I code into valid XHTML/CSS. Professional PSD, PNG or HTML to tableless XHTML/CSS designs. For more info, send me a PM. |
| |
| | #7 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | The following will work. All you have to do to change it is change $download_folder to the server path to your download folder (with a trailling slash) and change the path in the chdir line to the server root path of your forum. Also you will see comments at the bottom where you will have to output the header and also where you output the content of the file. If the file is large as you have already stated then increase your script maximum execution time using a line similar to the following (changing the 300 to the number of seconds you want it to run for):- PHP Code: PHP Code: |
| |
| | THREAD STARTER #8 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | hey guys great so far it works ![]() but i cant seem to get the header thing to work...how do i make it so that ANY file can be downloaded [like in the php manual..they specify that its a PDF] ? i know that mostly i will be uploading .ZIP and .RAR files also..second question..how do i make it that it uses the Vbulletin theme and stuff..so that it looks like a part of vbulletin forum...like on namepros...u have the domain management which is embeded in vbulletin
__________________ |
| |
| | #9 (permalink) | ||||
| Senior Member Join Date: Mar 2005
Posts: 4,948
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
????: NamePros.com http://www.namepros.com/showthread.php?t=311178 For 3.5.x or 3.6.x something like: PHP Code:
Last edited by SecondVersion; 04-20-2007 at 07:45 PM.
| ||||
| |
| | THREAD STARTER #11 (permalink) | ||||
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
__________________ | ||||
| |
| | THREAD STARTER #12 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | hey looking at the vbadvanced portal i made this: PHP Code: p.s: yes now i have 3.6
__________________ |
| |
| | #13 (permalink) |
| Senior Member Join Date: Nov 2005 Location: on a oil rig just off Ireland
Posts: 1,408
![]() ![]() ![]() ![]() ![]() | Link to another page that has php...
__________________ You design in photoshop, I code into valid XHTML/CSS. Professional PSD, PNG or HTML to tableless XHTML/CSS designs. For more info, send me a PM. |
| |
| | #16 (permalink) |
| Account Closed Join Date: Nov 2006 Location: Uk
Posts: 601
![]() | you save the first script into a folder, and the template into your template folder. then make sure the link to the temp. at the bottom of the script is right, and by the sound of it you should be good to gm. though i might be wrong, i know nothing about VB. |
| |
| | THREAD STARTER #17 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | the page works...but the program is...that the output from the php file is shown at the very top ...and the output in the template is shown where it should be...but i cant use php in the template
__________________ |
| |