Ask a Question related to Perl / CGI, Design and Development.
-
Toby Corballis #1
Read a text file on a user's machine and write to the screen (HTML)
Hi folks, this is driving me nuts so I do hope someone can help. It seems to me that this should be simple but everything I try I get: No such file or directory
What I want to do is read a text file from a user's machine and write the contents to a new page that I display. Here is (my not so elegant) initial script (though this will be tidied up once it works):
# Print the file upload form
print qq{<FORM ENCTYPE="multipart/form-data" ACTION="xxxxxx.pl"\n
METHOD="POST"> <p>${sfont}Please select the log file you want to process:${efont}<BR>\n
<INPUT TYPE="FILE" NAME="file"> <p> <INPUT TYPE="submit"> </FORM>} ;
Now the relevant bits from the next script (xxxxxx.pl):
use strict ;
use CGI::Carp qw/warningsToBrowser fatalsToBrowser/ ;
use DBI;
use File::Basename;
my $file = param('file') ;
$file=~m/^.*(\\|\/)(.*)/;
my $infile = upload('file');
open(FILE, "<$infile") or die "$!" ;
At which point is dies with the following message on screen:
No such file or directory
I cannot fathom it for the life of me
. Before I go completely bonkers and pull the one remaining hair out, can anyone help?
Many thanks
Junior Member
- Join Date
- Nov 2010
- Posts
- 2
-
Unable to read/write to .ini file using .dll in webservice
Hi, I am new to asp.net. I am creating a web service. This I havedone. The web service calls one of our .dll's. This .dll usesthe... -
File system get auto change from read-write to read-oly
I have a very strange file system with OS Redhat 7.2 The file system is read-write, but some how it randomly changes to read-only at any time.... -
read/write binary file
I'm writing a web service which will return a string containing the contents of a binary file (converted using System.Convert.ToBase64String). When... -
How do you make a fireworks html file to write text in?
or you could slice out the middle of the square where you want to have text, export the html into dreamweaver, click on the center slice, copy the... -
Read the contents of a text file into an HTML page
"Dutch3001" <mandygretahello@msn.com> wrote in message news:57c4bcf5.0307182134.78d05a86@posting.google.com... html wont do it, and client side... -
malcomosx #2
Re: Read a text file on a user's machine and write to the screen (HTML)
Hello Toby
I hope this helps, its a bit of code i use my self
and the actual perl bits to save the file that go into the perl scriptCode:<form action='../cgi-bin/update/getupdate.pl' method='post' enctype='multipart/form-data' target='updateFrame'> <b>Update Firmware </b><hr> <input type='file' name='getthisfile'><input type='submit' name='buttona' value='Update'> </form>
ChrisCode:use CGI ':standard'; my $query = new CGI; my $upload_filehandle = $query->upload("getthisfile"); $ps=$ps.$upload_filehandle; open ( UPLOADFILE, "> /mnt/img/update.pl" ) or print "\nERROR: Unable to create new file (Not uploaded) <br>\n"; binmode UPLOADFILE; while (<$upload_filehandle>){ print UPLOADFILE; } close UPLOADFILE;
Junior Member
- Join Date
- Dec 2010
- Location
- Ontario
- Posts
- 2
-
Toby Corballis #3
Re: Read a text file on a user's machine and write to the screen (HTML)
Thanks Chris. For some unknown reason I couldn't get anything to work until I stopped trying to open the file. So what ended up working was to get the name of the file from CGI, then treat it as a bytestream:
my $infile = upload('file'); # Get the special file handle from CGI
my $filesize = -s $infile ; # Get the file size
# File handling varaiables
my ($bytesread, $buffer, $str, $hex, $rec_size) ;
$bytesread = read($infile, $buffer, $filesize) ; # Have to read the whole file at once
# The loop round until the end of file is hit
while ($i <= $filesize) {
$chk = substr $buffer, $i, 1 ;
$hex = unpack('H*', $chk) ; # Get the hex representation of the current character
if ($hex eq '0a') { # We've hit the CRLF character so put rec into an array
$end = $i - $start ; # Set the length of the record
.... do stuff
$start = $i+1 ; # Increment the start parameter
#push (@records, $rec) ; # Get the record into the array
}
Odd but it worked.
Junior Member
- Join Date
- Nov 2010
- Posts
- 2



Reply With Quote

