LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2005, 06:18 AM   #1
apt
Member
 
Registered: Dec 2004
Posts: 34

Rep: Reputation: 15
Perl Script to download file


I have a perl script that has become available through my Hosting company.

Its function is to send and email to a user and then redirects to a another page. And its has no problem with it.

Code part which redirects to another page.
Code:
#### Redirect if "next-url" is included
if ($FORM{'next-url'}) {
    print "Location: $FORM{'next-url'}\n";
    print "\n";
    exit;
}
But now I want it to do a download first, before it redirects to the other page.

Is that possible, in perl script.?



Thanks in advance.
 
Old 10-18-2005, 03:43 PM   #2
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Rep: Reputation: 30
It is possible, although I know _no_ Perl whatsoever. Take a look at this script I found:
Code:
Code from File Download Script blahblahblah...

#!/usr/bin/perl -wT

use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);  

my $files_location;  
my $ID;  
my @fileholder;

$files_location = "/usr50/home/webdata/photos";

$ID = param('ID');

if ($ID eq '') {  
print "Content-type: text/html\n\n";  
print "You must specify a file to download.";  
} else {

open(DLFILE, "<$files_location/$ID") || Error('open', 'file');  
@fileholder = <DLFILE>;  
close (DLFILE) || Error ('close', 'file');  

open (LOG, ">>/usr50/home/webdata/public_html/test.log") || Error('open', 'file');
print LOG "$ID\n";
close (LOG);

print "Content-Type:application/x-download\n";  
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
}
Ok, it does much more than what you want to do, but I think that if you take a better look at it you may be able to understand some parts (ie. the bits you need).

I _think_ that you'd need to put in something like the following:
Code:
#Declare a variable
my @fileholder;

#Download the file
print "Content-Type:application/x-download\n";  
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
Please note that I don't have the foggiest idea if that'll work or not, I just didn't want to leave this thread unanswered.

M.
 
Old 10-19-2005, 08:19 AM   #3
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks J_K9 for your prompt reply.

Code:
#### Redirect if "next-url" is included

#Download the file
print "Content-Type:application/x-download\n";  
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder

if ($FORM{'next-url'}) {
    print "Location: $FORM{'next-url'}\n";
    print "\n";
    exit;
}
I tried with the code u had mentioned to download the file before redirecting to next URL. It just downloading a file or redirecting to another URL.

I want it to do both the tasks at a time. i.e to start download a file first and then it should be redirected to other page.

Any solution?

Last edited by apt; 10-19-2005 at 08:21 AM.
 
Old 10-19-2005, 08:25 AM   #4
J_K9
Member
 
Registered: Nov 2004
Distribution: Slackware 11, Ubuntu 6.06 LTS
Posts: 700

Rep: Reputation: 30
I don't know any Perl whatsoever, so I'm sorry about that. I guess you could set a timer on the redirect so that it waits a while for the download to finish. (You could also supply a link on the page for the redirect to be made manually if it is taking too long because of the timer). I admit this way is very crude, but it's the only thing I can think of.

I really have a clue what functions are pre-available in Perl, sorry. You could always make the program go on a loop until it can 'see' that the file's been downloaded! Hehe....

<experienced Perl programmer please post below>
 
Old 10-19-2005, 08:33 AM   #5
apt
Member
 
Registered: Dec 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks J_K9 for your suggestions.

Ok i will look into other possible solutions before continuing this one.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl cgi Script can`t make file.Why? ZairSadiqov Linux - Software 1 11-22-2006 07:22 AM
include a file in perl script Ateo Programming 1 04-22-2005 09:53 PM
executing perl script through .forward file skverma_in Linux - Newbie 3 10-21-2004 07:24 AM
executing perl script through .forward file skverma_in Linux - General 0 10-18-2004 05:06 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration