473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Question: Does any know

3
Does anyone know if perl can be used to hide a URL when someone downloads a file?
Mar 11 '08 #1
4 991
KevinADC
4,059 Expert 2GB
Yes it can.
Mar 11 '08 #2
achild
3
Great can anyone direct me to a module that helps do this? or a site where I can find more information on how to do this?
Mar 11 '08 #3
KevinADC
4,059 Expert 2GB
There is no module I know of that specifically does this. What you do is put your files in a directory that is not web accessible and have your perl script open the file and write the appropriate headers to download a file. The result is that the user has no idea where the file actually comes from. Here is a bare-bones script I wrote that does this:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2. use strict;
  3. use warnings;
  4. use CGI; 
  5.  
  6. my $q = CGI->new;
  7. my $file = param('file') or error('No file selected');
  8. my ($name,$ext) = $file =~ /^([^.]+)\.(.*)$/; 
  9. my $path_to_files = '/home/you/data';
  10. my $filesize = -s "$path_to_files/$file";
  11.  
  12. open(DLFILE, "<" , "$path_to_files/$file") or error('Error: Unable to find or open file');
  13.  
  14. print "Content-length: $filesize\r\n";
  15. print "Content-Type: application/x-download\r\n";
  16. print "Content-Disposition: attachment;filename=\"$file\"\r\n\r\n";
  17.  
  18. print <DLFILE>;
  19. close (DLFILE);
  20.  
  21. sub error {
  22.    print $q->header;
  23.    print shift; 
  24.    exit;
  25.  
The user selects a filename from a list of files in a form or hyper links, the field should be named 'file'.

Here you define the path to where the file are stored on the server:

Expand|Select|Wrap|Line Numbers
  1. my $path_to_files = '/home/you/data'; 
this should be above the web root. The script goes in the cgi-bin or wherever you run CGI scripts from. It is called from the forms action attribute or from the hyperlink:

Expand|Select|Wrap|Line Numbers
  1. <a href="download.pl?file=frog.jpg">download frog.jpg</a>
The CGI module can also write the headers for a file download you can look that up in the CGI documentation.
Mar 11 '08 #4
achild
3
This is a great help thank you very much Kevin. Very very helpful. :)
Mar 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

43
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
46
by: sbayeta | last post by:
Hi, I'd like to know who is responsible of memory recycling and defragmentation in a C/C++ program, assuming all the memory allocation/deallocation is done using malloc/free or new/delete. ...
15
by: designconcepts | last post by:
bo'jour, bo'jour, So I have question to present to the forum about OOD. This is a Csharp forum, but C# is the lang of choice and the question is an exercise based on some comments by the chief...
11
by: Random | last post by:
I'm confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
37
by: Prafulla T | last post by:
Assume that an integer pointer x is declared in a "C" program as int *x; Further assume that the location of the pointer is 1000 and it points to an address 2000 where value 500 is stored in 4...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.