WebFaction
Community site: login faq

I am looking for a script that can be used with a Static/CGI/PHP webfaction application that will allow me to serve a file for download only if a user first clicks through and accepts an agreement whose text is configurable. The user need not be registered.

Does any one have any suggestions? TIA for your help.

asked 14 Nov '10, 20:14

Farrukh
134
accept rate: 0%

Hi Farrukh,

I don't know of a script that does all of that, the easiest way would be to push a cookie to the users' browser that allows them to download the file. I haven't seen any scripts that actually do that out of the box.

(14 Nov '10, 20:33) klynton

Thanks for the suggestion Klynton. I do not know enough about CGI programming to know how to implement your suggestion.

I just assumed this is something simple and easily done because I see it in so many web sites.I do not know CGI programming but it seems like this should be easy. I am still hoping that someone knows a good solution.

(14 Nov '10, 20:49) Farrukh

Here is one possible solution that looks relevant... Will post after trying it out:

http://www.bluesparks.com/download.php?file=download.zip

(15 Nov '10, 06:57) Farrukh

The script suggested in my last post seems to be inadequate because it allows a user to access the download file via a direct URL and bypass the license. Can any one familiar with PhP tell me how easy is it to fix the scrip so direct URL to file is not exposed. Thanks.

(15 Nov '10, 07:43) Farrukh

Since I have a drupal site this drupal plugin looks relevant:

http://drupalmodules.com/module/webform-protected-downloads

Will post my findings after evaluation.

(15 Nov '10, 07:55) Farrukh

Assuming your file is not available through the web (out ot web-root, or protected by .htaccess), you can send it as attachment.

Let's say full path in the filesystem is in variable $filepath, it's size in bytes in $filesize and desired file name in $filename, code may look like this:

// sending headers
header('HTTP/1.1 200 OK');
header('Status: 200 OK');
header("Content-Length: $filesize");
header('Content-type: application/force-download');
header('Content-Disposition: attachment; filename="'.$filename.'"');
// sending file
readfile($filepath);

Script that executes this stuff should accept some identifier or maybe file name, so you can grab the path somehow. Possibly store in the database and use primary key for URL: ?fileid=XXX

Warning: this is NOT most efficient approach and may work slowly for large files, plus it uses your Apache slots for whole downloading time, for Webfaction this value limited to 5 connections per second.

Any way, hope this describes the idea.

permanent link

answered 16 Nov '10, 10:21

Sergii
525
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×31
×20
×1

question asked: 14 Nov '10, 20:14

question was seen: 3,188 times

last updated: 16 Nov '10, 10:21

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM