Solved

file download and authentication

Posted on 2000-03-03
11
170 Views
Last Modified: 2010-03-05
There are lots of websites offering files to be downloaded, but only after you login correctly. May I know how do I do this in cgi/perl? i.e. how to hide the path of the file? Or I have to write a script to 'stream' the file to the browser?
0
Comment
Question by:wyldsj
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 3

Expert Comment

by:guadalupe
ID: 2579937
A simple suggestion is that you simply have a perl which when it recieves a file request copies it to a temp directory, starts the download and kills the file when done.... Is simple but sometimes thats the best....
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 2580955
open FILE,"</path/file" or die "can't open file $!";
print $query->header(-type=>'application/octet-stream');
while( <FILE> ){ print }
0
 
LVL 3

Expert Comment

by:guadalupe
ID: 2581125
ozo,

I assume you mead to say that wyldsj should use the CGI module like so:

use CGI;

$query = new CGI;

No?
0
 

Author Comment

by:wyldsj
ID: 2582181
Thanks, both.
However,when I try the method using IE, my browser shows the file content directly (the binary rubbish). Also, I guess there must be somewhere in the script to tell the browser the file name to be downloaded. Anything missing?

Thanks again!
0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2585590
1
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:romio
ID: 2585802
there are many methods
the simple one is to use cookie
so when some one registers you set
him a cookie then the script which
promt to download will check for cookie
if there is a cookie it will promt to
download else it will redirect to registration page
this way mach more faster than i saw
people wrote and it doesn't matter
weather user can see the path or not
in both cases he won't be able to download it.

there is more complicated way like
to play with file permission
but this in case you are the root of
the server if you want more information
mail.
0
 

Author Comment

by:wyldsj
ID: 2586011
>> then the script which promt to download will
>> check for cookie if there is a cookie
>> it will promt to download else it
will redirect to registration page

I am not worrying about the authentication method. I am worrying about how to write a script to "prompt to download". ozo's method works great for me except for the filename.
0
 

Expert Comment

by:powerlord
ID: 2586320
Well, the browser actually tends to use the last part of the download path... which means you pretty much have to use GET instead of POST.

That's how I got it to work, at any rate.

Here's an example of a URL that should name the file correctly:

http://www.aserver.com/cgi-bin/download.pl?file=something.zip

Most browsers would grab something.zip as the file name.

Note, if that doesn't work, you can also use
http://www.aserver.com/cgi-bin/download.pl/something.zip

which would put the file name in $ENV{'PATH_INFO'}
0
 

Expert Comment

by:romio
ID: 2586854
then i'm sorry you would like to explain
your self better next time  as i understood you was worry
about people who would be able to download with out registration and not how to promt to download
0
 

Author Comment

by:wyldsj
ID: 2587043
Thanks powerlord, it works!
Looks like the answer is a combination from ozo, guadalupe and powerlord. Please let me know whom I should give the credit to.

Thanks to your experts!
0
 

Author Comment

by:wyldsj
ID: 2594517
i guess this is the most important part of the answer.. :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
perl to mysql 5 128
Filtering a file to table 9 98
Perl script not writing to .csv file 6 99
batch script for automated email 12 95
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now