Perl Script - Uploading A File

liunx

Guest
Hi Guys,<br /><br />I've spent hours on this, checked and rechecked. I hate asking for script help ... I feel like I failed.<br /><br />The script I have has worked on another host, but I had issues with uploading a file with TCH from the start. Not sure why. I tried revamping it some, but it's just so darn simple it should work.<br /><br />Anyway here is the script. It's a subroutine that receives a file name from a form:<br /><br />#!/usr/bin/perl<br /><br />sub subgetimagefile {<br />##### Read in the image file #####<br /> my ($imagefile) = @_;<br /> print "Image filepath length: ".length($imagefile)."<br>";<br /> print "Image File: $imagefile<br>";<br /> my $size=0;<br /> my $data;<br /> while (my $bytesread = read($data, my $buffer, 1024) or die("Error uploading file: $!\n")) { <br /> print "Reading: $size<br>";<br /> $size+=$bytesread;<br /> $content.=$buffer;<br /> print "Read: $size<br>";<br /> } <br /> return $content;<br /><br />}<br />return 1;<br /><br /><br />***************<br />Here is what I get when I try to use it after selecting a file.<br />***************<br /><br />Image filepath length: 44<br />Image File: C:\WINDOWS\Desktop\Ian Parker Hermonat 2.jpg<br />Content-type: text/html <br />Software error:<br />Error uploading file: Bad file descriptor<br /><br /><br /><br />Anybody else get these types of errors? Please help.<br /><br />Thank you,<br /><br />Bill<!--content-->
Bill from the error it looks like it's not taking into account the MIME type for a .jpg.<br /><br />I had a script I used to use that used binmode to upload.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->    <br />while ($bytesread = read($filename,$buffer,1024)) {<br />        $totalbytes += $bytesread;<br />        binmode OUTFILE;<br />        print OUTFILE $buffer;   <!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />This scipt required the CGI.pm module.<!--content-->
Hi Bruce,<br /><br />Thanks for the suggestion, but from what I can tell I don't think that's it.<br /><br />It's like it's having a problem opening the file or getting to it. It never outputs the first "print" to show that it is reading the file.<br /><br /> <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> It's just weird. Like it's having trouble making the connection.<br /><br />Maybe I'm just stuck in the way I'm looking at it. But even if I comment out anything with what it does with the file it still gives the error. It just won't read the file.<br /><br /> Yuck! Any other suggestions are welcome!<br /><br />Bill<!--content-->
Aparently I've found my answer.<br /><br />I tried to break the file load routine up and have it be a subprogram. However, this just didn't work.<br /><br />The perl code, for a lack of a better explanation, just seemed sensitive.<br /><br />I would work inside, in-line, but when made a subprogram, it bombed out with the error.<br /><br />I've got it working now.<br /><br />Thanks for trying!<br /><br />Bill<!--content-->
 
Back
Top