Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Perl CGI to download files via web browser

by tanuj (Novice)
on Mar 08, 2013 at 14:22 UTC ( [id://1022433]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl CGI to download files via web browser
in thread Perl CGI to download files via web browser

i was trying with the below code:
#!/usr/bin/perl #print "Content-type: text/html\n\n"; my $filepath='/upload/testing.pm'; print "Content-Type: text/html\n\n"; open("DOWNLOADFILE", "<".$filePath); while($fileContents = <DOWNLOADFILE>) { print $fileContents; } print "Content-Type: text\n"; print "Content-Disposition: attachement; filename='testing.pm'\n"; print "Content-Description: File to download\n\n"; close DOWNLOADFILE;

Replies are listed 'Best First'.
Re^5: Perl CGI to download files via web browser
by hippo (Bishop) on Mar 08, 2013 at 18:12 UTC

    Problem 1: You're printing two Content-Type headers. Solution: lose the first one.

    Problem 2: You're printing the content before the headers. Solution: swap them around.


    Update:

    Problem 3: The content type should probably be a full MIME type such as "text/plain".

      Thanks for suggesting the solution ...I got the script working ...
      use CGI; my $html= new CGI; my $file= $html->param('a'); my $filepath= "/var/www/upload/$file"; print ("Content-Type:application/x-download\n"); print "Content-Disposition: attachment; filename=$file\n\n"; open FILE, "< $filepath" or die "can't open : $!"; binmode FILE; local $/ = \10240; while (<FILE>){ print $_; } close FILE; #unlink ($filepath);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1022433]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-19 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found