Hi all,
I'm trying to increment the number of download cookie before download file action happens(or after) but forcing download is not working anymore. If I run the code separately then it works fine. I think "print cookie" is causing the download file here. Instead to popup the download window, it just write file content(all junk characters) to browser.
Can anyone done this before or have any idea how I can write cookie and force download?
See below my code
$cookie = $cgi->cookie (
-name => 'num_down',
-value => $new_numdl,
-expires => '+1y',
-domain => '.mydomain.com'
);
print $cgi->header(-cookie=>$cookie);
open(DLFILE, "<$filepath/$filename") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/) {
print "Content-Type: application/x-download\n";
} else {
print "Content-Type: application/octet-stream\n";
print "Cache-Control: no-cache\n";
}
print "Content-Disposition: attachment; filename=$x_filename\n\n";
print @fileholder
I'm trying to increment the number of download cookie before download file action happens(or after) but forcing download is not working anymore. If I run the code separately then it works fine. I think "print cookie" is causing the download file here. Instead to popup the download window, it just write file content(all junk characters) to browser.
Can anyone done this before or have any idea how I can write cookie and force download?
See below my code
$cookie = $cgi->cookie (
-name => 'num_down',
-value => $new_numdl,
-expires => '+1y',
-domain => '.mydomain.com'
);
print $cgi->header(-cookie=>$cookie);
open(DLFILE, "<$filepath/$filename") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/) {
print "Content-Type: application/x-download\n";
} else {
print "Content-Type: application/octet-stream\n";
print "Cache-Control: no-cache\n";
}
print "Content-Disposition: attachment; filename=$x_filename\n\n";
print @fileholder