×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Uploading large files = problem

Uploading large files = problem

Uploading large files = problem

(OP)
Hey, I posted about making new directories and the mkdir thing worked out after setting everything up correctly to work with the mkdir.  However, when I try to upload (really it's just coping to another folder on my computer while I test it) it doesnt work.  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.  Smaller files however, work fine.
Please help.
Source code below.
-----------------------
## path to where files uploaded.
$basedir = "c:/test";


## allow all file types?  yes/no
$allowall = "yes";

## If the above = "no"; then which is the only extention to allow?
$theext = ".txt";

## The page to forward to when done:
$donepage = "http://127.0.0.1/cgi-bin/test.pl";;







use CGI;
$onnum = 1;

while ($onnum != 11) {
my $req = new CGI;
my $file = $req->param("FILE$onnum");
my $filedir = $req->param("filedir");
if ($file ne "") {
my $fileName = $file;
$fileName =~ s!^.*(\\¦\/)!!;
$newmain = $fileName;
if ($allowall ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") {


mkdir ("$basedir/$filedir",0777);
open (OUTFILE, ">$basedir/$filedir/$fileName");
print "$basedir/$fileName<br>";
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
}
}
$onnum++;
}

print "Content-type: text/html\n";
print "Location:$donepage\n\n";

RE: Uploading large files = problem

You set your buffer for one meg.

while (my $bytesread = read($file, my $buffer, 1024))

Set it higher.  Eg: 2048 = 2 megs.

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Uploading large files = problem

Tom,

I think you may be mistaken there (or *I* might be <grin> it's happened before).

Read() takes 4 arguments

read FILEHANDLE,SCALAR,LENGTH[,OFFSET]

OFFSET is optional,
LENGTH is in bytes - not K
FILEHANDLE -- not a string containing a filename

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.

Try replacing the line:

while (my $bytesread = read($file, my $buffer, 1024)) {

with:

open(INFILE,$file) or die "can't open $file, $!\n";
while (my $bytesread = read(INFILE, my $buffer, 1024)) {

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site

RE: Uploading large files = problem

Mike, I'm sure you're right.  But if that is not where the problem is, then it's surely another buffer problem.  It almost always is when moving files around.  I bet the buffer is in the CGI module.  I think there is a $cgi->setbuffer() function or something similar.  Try inserting this code to see what's happening:

    my $error = $req->cgi_error;
    if ($error)
    {
print $req->header(-status=>$error),
      $req->start_html('Problems'),
              $req->h2('Request not processed'),
      $req->strong($error);
        exit 0;
    }

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Uploading large files = problem


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.  I'm not doing anything special.????


$newFile = 'someName';
open(OPF,">$newFile") ¦¦ &showError("Failed to open OPF, $!");
while ($bytesread=read($fileID,$buffer,1024)) { print OPF "$buffer"; }


'even tried setting the LENGTH to 1, and it still worked.....




keep the rudder amid ship and beware the odd typo

RE: Uploading large files = problem

(OP)
man this is frustrating.  I;ve tried everything that you all have suggested and I;m still getting zilch.  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.  RRRggghhhhh....

Anymore ideas anyone?  I'm opting to strap an EMP greande to my HD and be donw with it.

RE: Uploading large files = problem

(OP)
Ok, this is weird.  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.  I went to check my target dir and my 8.something meg file was there.... as a 1Kb file.  The filename and extension was intact but it was, well.... 1Kb.  Any ideas on what's going on there?  


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.  :)

RE: Uploading large files = problem

Did you get a return value for cgi_error?  What was it?

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Uploading large files = problem

(OP)
When you ask about my $FileID, do you mean that if the file I want is C:\blah.exe then $FIleID = "blah.exe"    
Or do you mean that my $FIleID would be "C:\blah.exe"  b/c right now it is the latter and not the former.
As for Tom's question, all that heppened when I added your code was that I got a 500 internal server error.  I didn't get any specific error msg other than that.

RE: Uploading large files = problem

I don't know why you'd get a 500 error, the syntax look OK.  Did you check your error_log?

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Uploading large files = problem

(OP)
I checked out my log and it basically said that there was a problem where I put your code.  I dunno what the hell is going on with this thing.

[Mon Aug 14 10:54:23 2000] [error] [client 127.0.0.1] Can't call method "cgi_error" on an undefined value at c:/program files/apache group/apache/cgi-bin/psupload.cgi

Thats the error in my error_log file.


*frantically tears out own hair, then realizes he has a date tonight and frantically searches for a bottle of Rogain.*


Methinks I'll just go watch the matrix for a while then come back to this....

RE: Uploading large files = problem

That code should go toward the end of your program, after you have declared $req and after you have had the problem.  By "undefined value" it sounds like $req hadn't been declared yet.

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: Uploading large files = problem

(OP)
Yeah, I realized my error as soon as I posted my last message and I corrected that.
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.

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.  RRGghhh.

RE: Uploading large files = problem

Mike,
I see what you are talking (writing) about.  The documentation for the 'read' function says it operates on a HANDLE, not a file name.  

However, when using CGI.pm.. when you do this to create the upload input field ...

print $query->filefield(-name=>'upload_file',
            -size=>'50',
            -maxlength=>'80');


....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.  So, you are correct.  The 'read' does operate on a HANDLE, it just appears to be operating on a name.

'hope this helps...




keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close