Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading large files = problem

Status
Not open for further replies.

DarkJedi

IS-IT--Management
Dec 13, 2001
10
GB
Hey, I posted about making new directories and the mkdir thing worked out after setting everything up correctly to work with the mkdir.&nbsp;&nbsp;However, when I try to upload (really it's just coping to another folder on my computer while I test it) it doesnt work.&nbsp;&nbsp;Whenever I try to upload files over 1 meg, my HTML doc works very slowly then after a long time finishes working, yet the file has not been copied.&nbsp;&nbsp;Smaller files however, work fine.<br>Please help.<br>Source code below.<br>-----------------------<br>## path to where files uploaded.<br>$basedir = &quot;c:/test&quot;;<br><br><br>## allow all file types?&nbsp;&nbsp;yes/no<br>$allowall = &quot;yes&quot;;<br><br>## If the above = &quot;no&quot;; then which is the only extention to allow?<br>$theext = &quot;.txt&quot;;<br><br>## The page to forward to when done:<br>$donepage = &quot;<A HREF=" TARGET="_new"> CGI; <br>$onnum = 1;<br><br>while ($onnum != 11) {<br>my $req = new CGI; <br>my $file = $req-&gt;param(&quot;FILE$onnum&quot;); <br>my $filedir = $req-&gt;param(&quot;filedir&quot;);<br>if ($file ne &quot;&quot;) {<br>my $fileName = $file; <br>$fileName =~ s!^.*(\\¦\/)!!; <br>$newmain = $fileName;<br>if ($allowall ne &quot;yes&quot;) {<br>if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){<br>$filenotgood = &quot;yes&quot;;<br>}<br>}<br>if ($filenotgood ne &quot;yes&quot;) { <br><br><br>mkdir (&quot;$basedir/$filedir&quot;,0777);<br>open (OUTFILE, &quot;&gt;$basedir/$filedir/$fileName&quot;); <br>print &quot;$basedir/$fileName&lt;br&gt;&quot;;<br>while (my $bytesread = read($file, my $buffer, 1024)) { <br>print OUTFILE $buffer; <br>} <br>close (OUTFILE); <br>}<br>}<br>$onnum++;<br>}<br><br>print &quot;Content-type: text/html\n&quot;;<br>print &quot;Location:$donepage\n\n&quot;;<br>
 
Tom,<br><br>I think you may be mistaken there (or *I* might be &lt;grin&gt; it's happened before).<br><br>Read() takes 4 arguments<br><br>read FILEHANDLE,SCALAR,LENGTH[,OFFSET]<br><br>OFFSET is optional,<br>LENGTH is in bytes - not K<br>FILEHANDLE -- not a string containing a filename<br><br>DarkJedi's code looks mostly ok to me, the logic is fine. Read() will return zero when there's nothing to read and the last time it *does* return data when it's probably not going to be LENGTH bytes long it shrinks SCALAR to fit.<br><br>Try replacing the line:<br><FONT FACE=monospace><b><br>while (my $bytesread = read($file, my $buffer, 1024)) { <br></font></b><br>with:<br><FONT FACE=monospace><b><br>open(INFILE,$file) or die &quot;can't open $file, $!\n&quot;;<br>while (my $bytesread = read(INFILE, my $buffer, 1024)) { <br></font></b><br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Mike, I'm sure you're right.&nbsp;&nbsp;But if that is not where the problem is, then it's surely another buffer problem.&nbsp;&nbsp;It almost always is when moving files around.&nbsp;&nbsp;I bet the buffer is in the CGI module.&nbsp;&nbsp;I think there is a $cgi-&gt;setbuffer() function or something similar.&nbsp;&nbsp;Try inserting this code to see what's happening:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;my $error = $req-&gt;cgi_error;<br>&nbsp;&nbsp;&nbsp;&nbsp;if ($error)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br> print $req-&gt;header(-status=&gt;$error),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$req-&gt;start_html('Problems'),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$req-&gt;h2('Request not processed'),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$req-&gt;strong($error);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br> <p> Sincerely,<br><a href=mailto: > </a><br><a href= Anderson</a><br>CEO, Order amid Chaos, Inc.<br>
 
<br>I experimented with it this morning a was able to upload a 7 meg tar file from my PC via a Netscape browser to a Sun box w/ Apache.&nbsp;&nbsp;I'm not doing anything special.????<br><br><FONT FACE=monospace><br>$newFile = 'someName';<br>open(OPF,&quot;&gt;$newFile&quot;) ¦¦ &showError(&quot;Failed to open OPF, $!&quot;);<br>while ($bytesread=read($fileID,$buffer,1024)) { print OPF &quot;$buffer&quot;; }<br></font><br><br>'even tried setting the LENGTH to 1, and it still worked.....<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
DarkJedi -- you still having the problem? <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
man this is frustrating.&nbsp;&nbsp;I;ve tried everything that you all have suggested and I;m still getting zilch.&nbsp;&nbsp;Wheverver I try to get it to work, my browser just chugs slowly along as I note the little progress bar growing ever so slowly closer to the right side of its range, until it finally does, the page redirects itself to the approprite finish page, yet the file has not been copied.&nbsp;&nbsp;RRRggghhhhh....<br><br>Anymore ideas anyone?&nbsp;&nbsp;I'm opting to strap an EMP greande to my HD and be donw with it.
 
Ok, this is weird.&nbsp;&nbsp;After waiting..... a good 2 - 3 minutes for my browser to finish doing whatever it was that it was doing, the file finished coping...... sort of.&nbsp;&nbsp;I went to check my target dir and my 8.something meg file was there.... as a 1Kb file.&nbsp;&nbsp;The filename and extension was intact but it was, well.... 1Kb.&nbsp;&nbsp;Any ideas on what's going on there?&nbsp;&nbsp;<br><br><br>Just in case I happen to stump all of you, I'll be charging up a few capacitors and wrapping some more cu wire around my gren.&nbsp;&nbsp;:)
 
DarkJedi,<br><br>How are you setting $fileID? <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
When you ask about my $FileID, do you mean that if the file I want is C:\blah.exe then $FIleID = &quot;blah.exe&quot;&nbsp;&nbsp;&nbsp;&nbsp;<br>Or do you mean that my $FIleID would be &quot;C:\blah.exe&quot;&nbsp;&nbsp;b/c right now it is the latter and not the former.<br>As for Tom's question, all that heppened when I added your code was that I got a 500 internal server error.&nbsp;&nbsp;I didn't get any specific error msg other than that.
 
I checked out my log and it basically said that there was a problem where I put your code.&nbsp;&nbsp;I dunno what the hell is going on with this thing.<br><br>[Mon Aug 14 10:54:23 2000] [error] [client 127.0.0.1] Can't call method &quot;cgi_error&quot; on an undefined value at c:/program files/apache group/apache/cgi-bin/psupload.cgi<br><br>Thats the error in my error_log file.<br><br><br>*frantically tears out own hair, then realizes he has a date tonight and frantically searches for a bottle of Rogain.*<br><br><br>Methinks I'll just go watch the matrix for a while then come back to this....
 
That code should go toward the end of your program, after you have declared $req and after you have had the problem.&nbsp;&nbsp;By &quot;undefined value&quot; it sounds like $req hadn't been declared yet. <p> Sincerely,<br><a href=mailto: > </a><br><a href= Anderson</a><br>CEO, Order amid Chaos, Inc.<br>
 
Yeah, I realized my error as soon as I posted my last message and I corrected that.<br>I'm not getting any errors now, not in my error log or as a result of the $error function that we added to the script.<br><br>I almost wish I was getting some errors, then I'd at lest have some idea why my 8 meg files are mysteriously shrinking to 1 k after talking 4 minutes to copy.&nbsp;&nbsp;RRGghhh.
 
What I mean about $FileID is that (and forgive me if I'm being stupid here) the first arugument to read() is supposed to be a file-handle, not a string containing a filename...<br><br>What am I missing? <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Mike,<br>I see what you are talking (writing) about.&nbsp;&nbsp;The documentation for the 'read' function says it operates on a HANDLE, not a file name.&nbsp;&nbsp;<br><br>However, when using CGI.pm.. when you do this to create the upload input field ...<br><FONT FACE=monospace><br>print $query-&gt;filefield(-name=&gt;'upload_file',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-size=&gt;'50',<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-maxlength=&gt;'80');<br></font><br><br>....the file name that is returned upon submission is also a file HANDLE........a little slight of hand on Mr. Stein's part, don't you think.&nbsp;&nbsp;So, you are correct.&nbsp;&nbsp;The 'read' does operate on a HANDLE, it just appears to be operating on a name.<br><br>'hope this helps...<br><br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Doh! &lt;bang&gt;&lt;bang&gt;&lt;bang&gt; (sound of head hitting desk), it's been a long week already... <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top