-1

Am going read and write the xml file. i upload the xml file using below html code. if i put the xml file in cgi-bin folder it will execute and display

 #!"C:\xampp\perl\bin\perl.exe"
     use strict;
use warnings;
use CGI;

my $cgi = new CGI;
print $cgi->header( "text/html" );

print <<END_HERE;
<html>
  <head>
    <title>My First CGI Script</title>
  </head>
  <body bgcolor="#FFFFCC">
    <p>Welcome to Perl CGI</p>

    <form action="/cgi-bin/inputxml.cgi" method="post"
    enctype="multipart/form-data">
    <p>Files to Upload: <input type="file" name="xml" /></p>
    <p><input type="submit" name="Submit" value="Submit Form" /></p>
    </form>
  </body>
</html>
END_HERE

But if i put the xml file in any other folder or drive (except cgi-bin folder) it shows Can't open data at C:/xampp/cgi-bin/inputxml.cgi

#!"C:\xampp\perl\bin\perl.exe"
            use strict;
            use CGI;
            use Cwd 'abs_path';
            use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
            use File::Basename;
            $CGI::POST_MAX;
            my $safe_filename_characters = "a-zA-Z0-9_.-";
            my $cgi = new CGI;
            print $cgi->header ( );
            my $file = $cgi->param('xml');
            my $lines;
            open(DATA,"<$file") or die "Can't open data $!";
            $lines = <DATA>;
            close(DATA);
            print $lines;    
            print abs_path($file);
            open(OUT, '>dirname($file)."\\out_".basename($file)');
            print OUT $lines;
            close(OUT);   
        print <<END_HERE;

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Thanks!</title>
    <style type="text/css">
    img {border: none;}
    </style>
    </head>
    <body>
    <p>Thanks for uploading your file!</p>
    </body>
</html>
END_HERE

print "Welcome Come Again";

i want to execute the xml file in any folder or drive without the cgi-bin folder please any one help, thanks in advance.

1

1 Answer 1

1

Let's try again.

This program runs on your web server. The path that you get from $cgi->param('xml') is the path on the client. It is extremely unlikely that the client path will exist on server - as your error message shows.

If you want to get the location of the uploaded file, you can use $cgi->tmpFileName($filename).

If you want a filehandle that is already open on the uploaded file, you can use $cgi->upload('xml').

If you want the name of the file that was uploaded then you can use $cgi->param('xml') - but you'll need to remove the directory path from the start of that value as it is useless to you on the server.

I explained all of this in answer to your previous question. But for some reason you seem to have ignored my previous answer. I'd be interested to hear why.

Sign up to request clarification or add additional context in comments.

2 Comments

Its working nice @Dave. I want the directory path of xml file. Because i want to write the output xml to the same location where am getting that xml file.I use this open $local_out_fh, '>', "$local_fn" or die $!; but the file is writing in cgi-bin folder only.
If you have an additional question, then it's probably best to start a new discussion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.