In the past, I used <@cgiparam> to determine the platform, then parsed  
the filename from the javascript method below. The only problem, is  
that there would be some WEBtv browser or something that would blow it  
up. I do several sites that are used by consumers, and it is very  
difficult to play with all the possible browsers. I try real hard to  
use code that will work on anything. So about a year ago I stopped  
using this method altogether. I do one of two things:

1. I create my own file name. Since I am accepting the binary data and  
have to write to a file and store the file name in a DBMS to reference,  
why use the uploaded file name? I create a file name based on a time  
stamp and/or random generated uid, and store the name in a database and  
write the file.

2. More often, unless these are very large files, I actually store the  
binary data as a blob in a table, give it a key of a generated uid (see  
my previous thread about creating uids).

Here is an example of what I mean. Lets assume we have a contact  
database, where you want to store the picture of someone in the db. In  
my experience, you want to use two tables so that you only call the  
image table when you need the image. You can use a one to one  
relationship:

Table One Schema: Contact Table

uid - integer - counter (primary key)
lastName - char50
firstName - char50
address - char 50
otherVariousContactFields
imageUID - char32

Table Two Schema: Contact Image Table
rowid - integer - counter (primary key)
uid - char32 - (candidate key)
image - blob
mime - char32 - stores the mime type of the image like "image/jpeg"

Now you have the image linked to the contact table. You must have a  
good dbms if you do this alot. It has a lot of benefits. Especially if  
you have multiple servers serving the content. They all hit the same  
dbms, no sync necessary. You can also do this creating a one to many  
relationship where the contactUID is referenced in the image table,  
allowing you to link an unlimited number of images to a single record  
in the contact table.

I have created several photography sites, image libraries, photo  
galleries, and real estate listing sites using these techniques  
allowing for the client or users to safely manage images, pdfs, and  
other binary assets.

One more note, the reason you store the mime type is for flexibility  
when serving the data. You can reference this column in the http header  
so that you can properly serve any binary type, either inline, or as an  
attachment. You may also add a field for content-disposition, or  
whatever variable needs to be set in the header.

Robert Garcia

On Sunday, September 8, 2002, at 12:21  PM, Garth Penglase wrote:

> I believe you are correct Robert, that you cannot get the filename  
> reliably with NAME="whateverfilename" since depending on the browser  
> and platform it could be the full path or not, and with either \ or /  
> used for the path. That is indeed why it is necessary to grab the  
> string in all cases and tokenise it to get the appropriate filename.
>
> I, for one, would love to get my hands on a complete solution for  
> this. How do you do it Robert? Do you do it entirely in javascript  
> (which seems to be the most efficient for detection of this sort of  
> thing, though probably beyond me as I am not an expert at writing  
> javascript) or do you use <@CGIPARAM> and create a separate action for  
> each platform/browser?
>
> Garth
>
>
> At 07:54  8/09/02, you wrote:
>> Yes, it is true that the browser will show in the text field just the
>> file name without the path. But that text field is not passed in the
>> form if the input type is file. What is passed is the binary info. The
>> filename can be retrieved with a hidden field and javascript like so:
>>
>> <FORM NAME="fileUpload" ACTION="<@CGI><@APPFILE>" METHOD="POST"
>> ENCTYPE="multipart/form-data">
>> File to upload: <INPUT TYPE="FILE" NAME="file">
>> <INPUT TYPE="HIDDEN" NAME="fileName">
>> <INPUT TYPE="BUTTON" VALUE="Upload"
>> onClick="document.fileUpload.fileName.value=document.fileUpload.file.v 
>> al ue;document.TheForm.submit();">
>> </FORM>
>>
>> The argument "fileName" will be the file name will be the filename  
>> with
>> the full path like so:
>>
>> win: c:\path_to_file\thefile.ext
>> mac os 9 and x: /path_to_file/thefile.ext
>>
>> The argument "file" will contain the binary data of the file.
>>
>> As far as I know the text that you see in the "file" field is not
>> passed at all.
>>
>> Robert.
>>
>> On Sunday, September 8, 2002, at 05:54  PM, JJ Smith wrote:
>>
>>> Thanks Robert,
>>>
>>> With ie 5.1.4 and OS 10.2 the value in the text box is
>>> just the filename and the extension.
>>>
>>> If the full path is being returned on Mac (whatever
>>> version) as described below then the tokenizing will
>>> be affected and the logic will have to be based on "/"
>>> rather than "\" as pointed out by by Robert
>>> previously.
>>>
>>> I thought I had got away with this but now I need to
>>> go back and put the "/" logic in to allow for Mac.
>>>
>>> Thanks again for pointing this out,
>>> JJ
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --- Robert Garcia <[EMAIL PROTECTED]> wrote:
>>>> I have, on OS 9 and OS X with IE 5+ the full path is
>>>> returned with the
>>>> "/" as the delimiter.
>>>>
>>>> Robert Garcia
>>>>
>>>> On Sunday, September 8, 2002, at 04:15  PM, JJ Smith
>>>> wrote:
>>>>
>>>>> Does it matter in this situation anyway as I
>>>> thought
>>>>> in IE on a Mac when you hit browse the full path
>>>> is
>>>>> not returned - just the filename and extension.
>>>> Thus
>>>>> in this case the tokenizing would still give the
>>>>> desired result.
>>>>>
>>>>> Can some mac people check when you hit browse and
>>>>> browse to the file whether or not the path is
>>>>> returned.
>>>>>
>>>>> Thanks in advance,
>>>>> JJ
>>>>>
>>>>> --- Robert Garcia <[EMAIL PROTECTED]> wrote:
>>>>>> No, even on OS 9, the file name from the browser
>>>>>> uses "/".
>>>>>>
>>>>>> Robert.
>>>>>>
>>>>>> On Saturday, September 7, 2002, at 09:37  AM,
>>>> Ford
>>>>>> Pedersen wrote:
>>>>>>
>>>>>>>> If you have any mac clients, you must determine
>>>>>> the platform first.
>>>>>>>> Mac uses "/", where windows uses "\".
>>>>>>>
>>>>>>> Slight correction. Mac OS 9 and below use ":".
>>>>>> Unix/Linux family & Mac
>>>>>>> OS X use "/". And Windows of course uses "\".
>>>>>>>
>>>>>>> HTH,
>>>>>>> Ford
>>> _____________________________________________________________________ 
>>> __
>>>>>>
>>>>>>> _
>>>>>>> TO UNSUBSCRIBE: send a plain text/US ASCII email
>>>>>> to
>>>>>>> [EMAIL PROTECTED]
>>>>>>>                with unsubscribe witango-talk in
>>>>>> the message body
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Robert Garcia
>>>>>> BigHead Technology
>>>>>> 2781 N Carlmont Pl
>>>>>> Simi Valley, CA 93065
>>>>>> Phone 805.522.8577
>>>>>> http://www.bighead.net/
>>>>>> http://www.theradmac.com/
>>>>>> [EMAIL PROTECTED]
>>>>>>
>>> _____________________________________________________________________ 
>>> __
>>>>
>>>>> _
>>>>>> TO UNSUBSCRIBE: send a plain text/US ASCII email
>>>> to
>>>>>> [EMAIL PROTECTED]
>>>>>>                 with unsubscribe witango-talk in
>>>> the
>>>>>> message body
>>>>>
>>>>>
>>>>> __________________________________________________
>>>>> Do You Yahoo!?
>>>>> Yahoo! Finance - Get real-time stock quotes
>>>>> http://finance.yahoo.com
>>> _____________________________________________________________________ 
>>> __
>>>>
>>>>> _
>>>>> TO UNSUBSCRIBE: send a plain text/US ASCII email
>>>> to
>>>>> [EMAIL PROTECTED]
>>>>>                 with unsubscribe witango-talk in
>>>> the message body
>>>>
>>>> --
>>>>
>>>> Robert Garcia
>>>> BigHead Technology
>>>> 2781 N Carlmont Pl
>>>> Simi Valley, CA 93065
>>>> Phone 805.522.8577
>>>> http://www.bighead.net/
>>>> http://www.theradmac.com/
>>>> [EMAIL PROTECTED]
>>>>
>>> _____________________________________________________________________ 
>>> __ _
>>>> TO UNSUBSCRIBE: send a plain text/US ASCII email to
>>>> [EMAIL PROTECTED]
>>>>                 with unsubscribe witango-talk in the
>>>> message body
>>>
>>>
>>> __________________________________________________
>>> Do You Yahoo!?
>>> Yahoo! Finance - Get real-time stock quotes
>>> http://finance.yahoo.com
>>> _____________________________________________________________________ 
>>> __ _
>>> TO UNSUBSCRIBE: send a plain text/US ASCII email to
>>> [EMAIL PROTECTED]
>>>                 with unsubscribe witango-talk in the message body
>>
>> --
>>
>> Robert Garcia
>> BigHead Technology
>> 2781 N Carlmont Pl
>> Simi Valley, CA 93065
>> Phone 805.522.8577
>> http://www.bighead.net/
>> http://www.theradmac.com/
>> [EMAIL PROTECTED]
>>
>> ______________________________________________________________________ 
>> __
>> TO UNSUBSCRIBE: send a plain text/US ASCII email to  
>> [EMAIL PROTECTED]
>>                with unsubscribe witango-talk in the message body
>
> _______________________________________________________________________ 
> _
> TO UNSUBSCRIBE: send a plain text/US ASCII email to  
> [EMAIL PROTECTED]
>                with unsubscribe witango-talk in the message body
>

-- 

Robert Garcia
BigHead Technology
2781 N Carlmont Pl
Simi Valley, CA 93065
Phone 805.522.8577
http://www.bighead.net/
http://www.theradmac.com/
[EMAIL PROTECTED]

________________________________________________________________________
TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
                with unsubscribe witango-talk in the message body

Reply via email to