Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: About how PERL scripts execute

by Macphisto (Hermit)
on Feb 10, 2003 at 20:20 UTC ( [id://234229]=note: print w/replies, xml ) Need Help??


in reply to About how PERL scripts execute

I ended up having to use a wee bit of Javascript to get this going. Firstly, I was doing it in mod_perl, so I don't know how well it'll translate into your project, but hopefully it'll help.

Each user that logged in got a 10 digit alphanumberic session ID ( $session_id ) associated with him and passed around as part of his cookie. I also had Apache::Request spool to a temporary directory with the TEMP_DIR parameter set to /tmp/$session_id. This gave me a quasi-unique( yes, the possibility exists that there would be a collision ) directory that I could query the size of. When the user clicked the submit button I used a window.open( There's the javascript, I don't like its inclusion, but it works ) to pop-up a smallish window that would execute a subroutine to check the size of the directory /tmp/$session_id, and report in in MBs to the user. One thing that I wasn't able to do was actually create a progress bar. The hitch was that I had no prior knowledge of the file size before I was querying the size of the directory the file was being uploaded to. Apache::Request will report the size of the file uploaded, but only after the file has been uploaded. If you could somehow attain the filesize before the file is uploaded, you'd be able to knock out a quick GD script to show a progress bar. If you do figure out how to do that( short of user input ) please, let me know. I'd be most interested. My solution is, by no means elegant, but it works. And the requirment my boss gave me was that it worked. Elegance, sadly had to take a back seat.

I hope this helps.
Mac

Everyone has their demons...you just happen to be mine.

Replies are listed 'Best First'.
Re: Re: About how PERL scripts execute
by Eoin Redmond (Novice) on Feb 12, 2003 at 00:13 UTC

    Mac

    This might be of interest to you as I have now managed to get the upload file name into a Perl script before the upload starts. I know javascript is the devil but I couldn't see any another way. Merlyn has a script using fork and CGI:FileCache which looks promising but I couldn't get it to run in a Win32 environment. Anyway, this is what I came up with:

    First the form:

    <form name="upload" action="filemngt_upload_file.pl" method="post" enc +type="multipart/form-data" onSubmit="showProgress()"> Enter the name of the file to uploaded: <input type="file" name="uploadfile" size="30"> <input type="submit" value="Upload File"> </form>

    As you can see from the above I have added the javascript event handle onSubmit which runs a javascript function called showProgress(). When the submit button is pushed the onSubmit event handler is processed before the main submit function. Here is the code for the showProgress() function:

    <SCRIPT LANGUAGE="JavaScript"> function showProgress() { var uploadfilename = document.upload.uploadfile.value; var newWindow = open("http://localhost/cgi-bin/test.pl?uploadfile=" + +uploadfilename, "secondWindow", "scrollbars,resizable,width=250,heigh +t=150,left=720"); } </script>

    Javascript allows you to access the name of the file for upload within a form. The line which begins with var = uploadfilename is where I'm setting a variable with the name of the file (which was entered by the user) for upload. I'm then opening a new window and calling a Perl script with the name of the file (to be uploaded) as a parameter.

    So I now have 2 Perl scripts running, one uploading the file and the other running (in another window) which knows the name of the file which is being uploaded so I can now add code to it to start monitoring the upload

    Hope this might be useful to you

    Eoin

    PS - All the above was tested (IE6) prior to this post

Re: Re: About how PERL scripts execute
by Anonymous Monk on Feb 10, 2003 at 22:27 UTC

    Thanks Mac

    By the way, I am a multi-user demon as many monks will testify!

    Eoin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found