473,322 Members | 1,259 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,322 software developers and data experts.

Help On File Download Script

rajiv07
141 100+
Hi To all, I have a script for downloading file from the server.The Problem is when i try to download WMA file it get download but it is not playing.when i try to play this file in Windows Media Player It gives the following error

Windows Media Player cannot play the file. The file is either corrupt or the Player does not support the format you are trying to play.


Here is My script

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl  
  2. use CGI;
  3. use CGI::Carp qw(fatalsToBrowser); 
  4.  
  5. my $cgi=new CGI;
  6. my $files_location; 
  7. my $ID; 
  8. my @fileholder;
  9.  
  10. my $files_location = "c:/perl/";
  11.  
  12. my $cFile = $cgi->param('file');
  13.  
  14. if ($cFile eq '') { 
  15. print "Content-type: text/html\n\n"; 
  16. print "You must specify a file to download."; 
  17. } else {
  18.  
  19.  
  20. my $cFile=$files_location.$cFile;
  21.  
  22.  
  23.  
  24. open(DLFILE, "<$cFile") || die "cannot open the File $! $cFile"; 
  25. @fileholder = <DLFILE>; 
  26. close (DLFILE) || Error ('close', 'file'); 
  27.  
  28. print "Content-Type:application/x-download\n"; 
  29. print "Content-Disposition:attachment;filename=$cFile\n\n";
  30. print @fileholder
  31. }
Is any chance the file get corrupt while downloading Or the Script is not efficient one.

Please Help On this.

Thank In advance.

Regards
RajivGandhi
Jan 17 '08 #1
4 2555
prn
254 Expert 100+
Hi Rajiv,

It is true that your script is not particularly efficient, but that is not the problem. It is also not the case that the file is corrupted during downloading.

The problem appears to be that your lines 24-30 open the file from your server, save the file as an array of lines of text and then print the file as lines of text to the output. Unfortunately, your file is not supposed to be treated as text.

I suspect that what you ought to do is found in the Perl FAQs.

Let us know if this isn't the problem.

Best Regards,
Paul
Jan 17 '08 #2
KevinADC
4,059 Expert 2GB
Your script is potentially a security risk. You perform no validation on the filename passed to the script:

my $cFile = $cgi->param('file');

A malicious user could try and pass in the path to a sensitive file and see if your script will blindly download it. The code you posted is probably not the final version, but I thought I would still mention the potential security risk in case you are not aware of it.
Jan 17 '08 #3
rajiv07
141 100+
Thanks Prn and Kevin,

could you please suggest me any tutorial to develop a exact script for file download.

Thanks.

Regards
RajibGandhi.
Jan 18 '08 #4
rajiv07
141 100+
Hi Rajiv,

It is true that your script is not particularly efficient, but that is not the problem. It is also not the case that the file is corrupted during downloading.

The problem appears to be that your lines 24-30 open the file from your server, save the file as an array of lines of text and then print the file as lines of text to the output. Unfortunately, your file is not supposed to be treated as text.

I suspect that what you ought to do is found in the Perl FAQs.

Let us know if this isn't the problem.

Best Regards,
Paul
Thank u So Much Prn,

Its working fine after adding this line before i read the file content.

Expand|Select|Wrap|Line Numbers
  1. binmode( DLFILE );
The Conclusion
On some systems (in general, DOS and Windows-based systems) binmode() is necessary when you're not working with a text file.

Thank U

Regards
RajivGandhi
Jan 18 '08 #5

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

Similar topics

0
by: Arg | last post by:
I posted this to alt.comp.lang.php last week and got no response so I am reposting it here today... I am trying to use the following script to allow users to download files with some of the file...
5
by: | last post by:
I am having a major problem with file transfers - they are ending early when the bandwidth tops-out. Smaller files transfer just fine, but large files (12Mb+) can 'abort' the transfer after maybe...
2
by: kevinm3574 | last post by:
So, I'm doing the following in a php script so that I can fire a download dialogue AND redirect the page (after clicking submit in a form). I'm doing it this way because of the problem with...
2
by: Mark Delon | last post by:
Hi, i want to log via python script to https page: 'https://brokerjet.ecetra.com/at/' # But it does not work. I am using following code(see below)
2
by: Good Man | last post by:
Hi there folks I've got an interesting little problem going on. On one of my projects, I have users log in to retrieve files. The files themselves are stored outside of the www directory on...
3
by: Chuck Renner | last post by:
Please help! This MIGHT even be a bug in PHP! I'll provide version numbers and site specific information (browser, OS, and kernel versions) if others cannot reproduce this problem. I'm...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
3
by: cuties | last post by:
Hi all.... i'm very new to this programming language. i'm required to fulfill this task in the company i'm doing my practical. i hope i can get guide for my problem... Here is the script i...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.