By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

File Upload Script

P: 55
hi all,
i have seen a program from web that is used to upload a file from particular directory..
My problem is that they have mentioned some file directory name in the program but when i am running the program, in the browser i am getting the directory is not valid..

In this program i have not involved to do any part,but i need to know about this code..

code for fileupload
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. print "content-type:text/html \n\n";
  4. print <<html_part;
  5. <html>
  6. <head>
  7. <script>
  8. function validate() {
  9.     if(document.test.file.value=="") {
  10.         alert("file name cannot be empty");
  11.         return;
  12.     }
  13.     document.test.submit(true);
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <FORM name="test" ENCTYPE="multipart/form-data" ACTION="upload.cgi" METHOD="POST">
  19. <p>
  20. Please select a file to upload: <INPUT TYPE="FILE" NAME="file">
  21. <p>
  22. <INPUT TYPE="button" value="submit_form" onclick="validate()">
  23. </FORM>
  24. </body>
  25. </html>
  26. html_part
  27.  
code for upload.cgi
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. print "content-type:text/html \n\n";
  3.  
  4. use CGI;
  5. my $cgi = new CGI;
  6.  
  7. my $file = $cgi->param('file');
  8. $file =~ m/^.*(\\|\/)(.*)/;
  9.  
  10. my $name = $2;
  11.  
  12. open(LOCAL, ">../sample/$name") or die $!;
  13. while(<$file>) {
  14.     print LOCAL $_;
  15. }
  16. print $cgi->header();
  17. print "$file has been successfully uploaded... thank you.\n";
  18.  

any help would be grateful..i can browse the file and attaching it, but it is not getting uploaded..
will u give me answer for this...
Jun 20 '07 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
I assume this line is the problem:

open(LOCAL, ">../sample/$name") or die $!;

"../sample" is just that, it is an example only. You need to change that to a valid directory on your server.
Jun 20 '07 #2

100+
P: 109
Hi...

Make sure the folder exists in ur server and that the permission is allowed to write to the folder..
Jun 25 '07 #3

Post your reply

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