Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^6: file upload and IO::Handle

by rowdog (Curate)
on Sep 09, 2010 at 17:52 UTC ( [id://859540]=note: print w/replies, xml ) Need Help??


in reply to Re^5: file upload and IO::Handle
in thread file upload and IO::Handle

I get this error message: Error reading Upload progress... which appears to be that hook is not starting I think.

I think it means the opposite: your hook is called but fails to read the session file. Your code looks like this...

if (-f "./$sessid.session") { # Read it. open (READ, "./$sessid.session"); my $data = <READ>; close (READ); print "$data"; } else { print "Error reading Upload progress..."; }

... so your error message is telling you that "./$sessid.session" is not a plain file. So the file isn't there or you don't have permission to read it or $sessid has a garbage value.

Also, you should check the return value of open and I would ditch the use of -f and just try to open the file instead...

if ( open my $read_fh, '<', "./$sessid.session" ) { my $data = <$read_fh>; close $read_fh; print "$data"; } else { print "Error reading session file for session $sessid: $!"; }

And finally, I agree with roboticus that you should stick with passing the session id in the form rather than using globals. What happens if one user starts a session and forgets about it and then opens another browser window and trys to upload something else? They wind up reusing the first session... havock ensues.

Replies are listed 'Best First'.
Re^7: file upload and IO::Handle
by Anonymous Monk on Sep 09, 2010 at 19:02 UTC
    No, the global session is based on their logged in username, since it is unique to the person logged in, then it will only be theirs... that is why I did that. it is not just a single name, it is their username.

    Since session is what it was using and they already have a session, I use Apache::MySql::Session, I went ahead and changed all of the code to that:
    #Was: (in sub hook): # Write this data to the session file. open (SES, ">./$sessid.session"); print SES "$bytes_read:$length:$percent"; close (SES); #Now (in sub hook): my $_ups = join(':',$bytes_read,$length,$percent); $sess_ref->attr("_uploadStatus_","$_ups"); #Was: (no sub, just in code [after upload complete]): # Delete the session file. unlink("./$sessid.session"); # Now in same place: # Delete the session value. $sess_ref->clear_attr("_uploadStatus_"); # last change: # Was if (-f "./$sessid.session") { # Read it. open (READ, "./$sessid.session"); my $data = <READ>; close (READ); print "$data"; } else { print "Error reading Upload progress..."; } #now: $data = $sess_ref->attr("_uploadStatus_"); if($data) { print "$data"; } else { print "1:1:1 No Session Value Found"; }
    Also of note, I see in hook, these values received in it:
    $filename,$buffer,$bytes_read,$file
    But I don't see a reference to hook passing those values to it. How does that work?

    Now 1:1:1 No Session Value Found prints... So I am thinking that hook is never even executed.

    What executes it?
    Thanks,
    Rich
Re^7: file upload and IO::Handle
by Anonymous Monk on Sep 09, 2010 at 19:11 UTC
    oops, I see what you said now, about the session and if they open a new browser window, did not read that line careful enough... I can fix that by not allowing another upload to start until the first is done.
    There will only be a few people that are allowed access to this, so I don't think they will need to use it to often. They are just uploading videos for product reviews, more then often they will be no more than 10MB, and he is on a super fast high speed connection so the upload should be fast enough for him to finish it before needing another.
    Using the code I changed it to, if I can get it to work, I can see if the _uploadStatus_ in the session exists if so, not build another form, and tell them to please wait until the other upload is completed, and then keep auto-refreshing that form with ajax until it is done so then it will rebuild the form so they can upload another.

    still need answered my other questions though, please, as I still cannot figure out hook, the values passed to it(or jus, received (why not passed, or where passed from?)) and what executes it.

    Rich
      I still cannot figure out hook, the values passed to it(or jus, received (why not passed, or where passed from?)) and what executes it.

      Well, CGI explains all that in Progress bars for file uploads and avoiding_temp files but what happens is, CGI has a socket for the upload, every time it reads a chunk from the socket, it calls the hook with the new data, which is where your parameters are coming from.

        Ok, I followed the CGI recommendation for setting it:
        $q = CGI->new(\&hook [,$sess_ref [,$use_tempfile]]);
        and I get this error:
        syntax error at /home/path/to/Files/file_upload_sys.data line 5, near +"&hook ["
        which is the line I showed you above...
        why does that not work? $sess_ref is the session reference to variable to use the session stuff, the CGI documetion says $data is optional and can be the database handle, so I figured I may as well pass the session reference so it can use the session they are in, to update the status. but the error happens.

        Also, inside of the hook, I have it open a temp file and write data to it, always appending it so that I can confirm it is reaching inside the hook, but nothing ever gets written and no die error is executed so I know it is just not getting executed. How could that be?

        Thanks again,
        Rich

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://859540]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found