| General Databases (71) Linux (42) Outside the Cube (2108) Programming (730) Web publishing (118) about DelphiFAQ (12) JavaScript (55) perl CGI (3) VBScript (1) Web Hosting (8) Windows (355) |
Original file name in a http file upload form
Question: I need to provide a file upload form on my web site and want to preserve the original file name.Right now the uploaded files arrive on my web server in the temp folder and have file names like /tmp/upload_12345.tmp /tmp/upload_12367.tmp How can I obtain the original file name? Answer: The http upload protocol does not capture the local file name on the client side. What you can do is to write some javascript function that hooks into the file upload field's onchange() event.There take the field's value (which will be the remote file name) and copy it into a hidden input field. The hidden input field will be passed as part of your form. You CGI script then can evaluate it and maybe do something useful with it. Possible values for the remote file would be: "c:\documents and settings\photo.jpg" "\\machine1\\c:\photo.jpg" "/home/peter/photo.jpg" and others, depending on the remote operating system. Your CGI script needs to be prepared for all these possibilities and - in the examples - it probably should extract 'photo.jpg' as the file name. The code below looks for the \ and for the / as path delimiters. Make sure to set the form's encoding attribute with enctype="multipart/form-data"
Comments:
|