I'm fairly green in terms on HTML, only been coding for about 6 months (in regards to HTML).
I'm writing a simple conversion utility to convert UNIX timestamps to normal everyday dates. Since <TEXTAREA> has a size limitation I have decided to use TYPE=FILE to upload a text file containting the UNIX timestamps into the CGI script and let the perl script process it from there. When I Browse to the text file, I always get:
"Error opening C:\unixtime.txt: No such file or directory"
I'm using a typical installation of IIS 5, do I need any other "plug-ins" whatever to get this to work? Or should it work "right out of the box"?
One other note... I'm not using ENCTYPE="multipart/form-data", because I'm sending this data right back to the same script.
My Incompleted HTML CODE:
#!i:/perl/lib -w
use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);
# Create new CGI object and print standard CGI header
$q = new CGI;
print $q->header;
$action = $q->param(action);
$filename = $q->param(filename);
print "<FORM METHOD='post' ACCEPT='text/html' ACTION='$form_action'>";
print "Select File to Convert from UNIX TIMESTAMP Format to Normal DATE Format:<BR>";
print "<INPUT TYPE=FILE NAME='filename' SIZE='75'><BR>";
print "<BR><P></P>";
print "<INPUT TYPE='submit' NAME='action' VALUE='Convert File'>";
if($action =~ /convert/i) {&convert;}
print "</FORM>";
exit;
############## Begin Subroutines
sub convert {
print "<P></P>$filename<BR>";
open(UNIXFILE, "<$filename") or die "Error opening $filename: $!\n";
@unixdata = <UNIXFILE>;
close(UNIXFILE);
print "<P></P>";
print "@unixdata";
#$normaldate = scalar localtime($unix)."\n";
# END of Code
Thanks,
Steve Thomas
#!/usr/bin/perl
use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);
# Create new CGI object and print standard CGI header
$q = new CGI;
print $q->header;
$action = $q->param(action);
$filename = $q->param(filename);
print "<FORM METHOD='post' ACCEPT='text/html' ACTION='$form_action'>";
print "Select File to Convert from UNIX TIMESTAMP Format to Normal DATE
Format:<BR>";
print "<INPUT TYPE=FILE NAME='filename' SIZE='75'><BR>";
print "<BR><P></P>";
print "<INPUT TYPE='submit' NAME='action' VALUE='Convert File'>";
if($action =~ /convert/i) {&convert;}
print "</FORM>";
exit;
############## Begin Subroutines
sub convert {
print "<P></P>$filename<BR>";
$normaldate = scalar localtime($filename)."\n";
print $normaldate;
}
# END of Code
I've tried using the double backslashes, but doesn't work. I've even tried hardcoding in the filename. As long as the file is on the IIS server (i:/inetpub/times/unixtime.txt), it works, but I can't get it to recognize a file on MY system.
I'm dealing with Log files here... machines that spit out a total of 2GB of text data a day. And all sequenced with UNIX timestamps, but to get it in a readable format, I need to see it in normal dates, and so do the VP's.
I can do it all manually, the perl script that has the file local on the server and the filenames coded into the perl script, but I want a little more flexibility.
Thank you all for your help.
Steve
Thanks.
I don't think this is possible. The usual way to do things is to upload into a temporary file, copy that file into a specific location and then do your crunching on it (then maybe delete it).
AFAIK there's no way around it, your script has to have write permissions for some directory on the server.
#!/usr/bin/perl
use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);
# Create new CGI object and print standard CGI header
$q = new CGI;
print $q->header;
$action = $q->param(action);
$filename = $q->param(filename);
unless ($filename ) {
print "<FORM METHOD='post' ACCEPT='text/html' ACTION='$form_action'>";
print "Select File to Convert from UNIX TIMESTAMP Format to Normal DATE
Format:<BR>";
print "<INPUT TYPE=FILE NAME='filename' SIZE='75'><BR>";
print "<BR><P></P>";
print "<INPUT TYPE='submit' NAME='action' VALUE='Convert File'>";
print "</FORM>";
exit;
}
else {&convert;}
############## Begin Subroutines
sub convert {
print "<P>";
print '<pre>';
@times = split(/\n/,$filename);
foreach $time(@times){
my $normaldate = scalar localtime($time);
print $normaldate . "\n";
}
print '</pre>';
exit;
}
# END of Code
My main problem is getting the IIS server/script to pull the data from my local harddrive. When the IIS/Perl script processes $filename, I believe it is trying to pull it from a local (server) location. When $filename is "C:\unixtime.txt", it doesn't realize $filename is local to the Browsing PC, it seems to want to from it's "C:\", which it doesn't exist. Even when I try to incorporate a copy of the local file to the server (within the script), it still tries to copy it from "C:\" from itself, and not the Browsing PC. Follow me?
Again, Thanks.
How are you setup? Meaning, are you running this script on a web server and accessing the the script through a browser on another computer? Which browser? The way your example script is, does it work properly by collecting the data from the client PC? That's my specific problem... it's not collecting the data from the client PC.
All of the references I've seen concerning useing TYPE="FILE" (in regards to <INPUT>), they state you must use ENCTYPE="multipart/form-data" parameter within the <FORM> tag. And so far nobody has complained that I haven't used it in my sample code... is it really needed? I've tried using it, and I get an interesting permission error in regard to "tmpfile". I've granted the webuser rights to write to the directory, but it still is giving me fits. Go figure.
If I'm getting the jist of this ... would a share do the trick? that way the file path could address the file location correctly, might have some security concerns though....
Or use LWP to "get" the file to the local machine then run your script on successful retrieval?
<added>now that I re-read this, neither of those may be useful :( </added>
I realize most of you guys use Unix (or some variation), and I would too if I had the opportunity. But NT is all I got to work with. Thanks.