p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   define location for file input tag (http://p2p.wrox.com/showthread.php?t=17080)

bleitner August 18th, 2004 07:07 PM

define location for file input tag
 
I asked this question in the other forum but didn't get any replies so I figured I'll try here. What I'm trying to do:

I have a form with a input element, type file. What I want to happen when a user clicks the Browse button to go get a file is for the "Choose File" dialog to open to a specified location defined by the script. For instance:

<form...>
<input name="Pic" type="file" onClick="getPic()">
</form>

in head...
function getPic() {
  myElement = document.form.Pic;
  path = "ftp://ftpsite/pictures/";
  myElement.value = path;
}

Is it possible to do this? If so, does anyone know how to achieve it?

thanx,
Bob



Imar August 19th, 2004 12:51 PM

Fortunately, you can't set the value of a file control.
Combined with this body tag:

<body onload="document.forms[0].submit();">

you could easily steal any documents you want, provided you'd know the name.

You also cannot upload from an FTP site. The input type="file" control uses a local or network path, but AFAIK, you cannot get it to upload files from an FTP server.

What exactly are you trying to accomplish?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

bleitner August 19th, 2004 01:12 PM

Quote:

quote:Originally posted by Imar
 Fortunately, you can't set the value of a file control.
Combined with this body tag:

<body onload="document.forms[0].submit();">

you could easily steal any documents you want, provided you'd know the name.

You also cannot upload from an FTP site. The input type="file" control uses a local or network path, but AFAIK, you cannot get it to upload files from an FTP server.

What exactly are you trying to accomplish?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

Thanks for responding. I didn't want to define an actual file name, just a directory, but that may not make a difference.

What I'm doing is for an Intranet, it's a quality control program that the qc person uses to enter certain info on the item their checking, including a picture if there's a problem. I have a form that collects information and a picture, and enters into a database. I didn't want to actually store the pic in the database (to keep the db size down and for ease) so I was planing to store the path to the picture. The pictures would be stored on a network drive in a folder. The user would use the file browse to go find the picture and then I just pass the path to the database. I didn't want the user to have to go and search the network for the path, especially on thin clients where I can't map drives, so I thought the solution would be to force the file open dialog to open to the folder where the pics are stored and then the user just has to pick the picture.

What would be really nice is if it's possible to tie a button on the form to the camera attached to the computer - just a little web cam, and when the qc person selects the button the picture is taken and entered into the form automatically - then I'll just stick the pictures themselves into the database. I don't know if that's possible, haven't looked into it yet.

Let me know what you think and if you have any other suggestions.

Thanks!
Bob



Imar August 20th, 2004 12:20 PM

Hi Bob,

Although you cannot set the value of the <input type="file"> control, you can read from it.

What you could do is write a little JavaScript function that retrieves the value from the file field, and stores it in a hidden field. You can call this function on onblur of the file field, or when the user clicks a submit button, for example.

Then, at the server, you can retrieve the name of the file from the hidden field. You may need to reset the file field to prevent the actual upload of the file.

You can only have a user select a real file, not a folder. So, unfortunately, when you want your users to select a folder, you'll have to make them point to a file inside that folder, and then at the server extract the folder name from the file name.

With normal HTML, you cannot retrieve a picture from a camera. Maybe if you write an ActiveX control, you could do it, but I haven't tried
anything like that before.

If you need help with the JavaScript solution, let me know.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

bleitner August 20th, 2004 09:00 PM

Quote:

quote:Originally posted by Imar
 Hi Bob,

Although you cannot set the value of the <input type="file"> control, you can read from it.

What you could do is write a little JavaScript function that retrieves the value from the file field, and stores it in a hidden field. You can call this function on onblur of the file field, or when the user clicks a submit button, for example.

Then, at the server, you can retrieve the name of the file from the hidden field. You may need to reset the file field to prevent the actual upload of the file.

You can only have a user select a real file, not a folder. So, unfortunately, when you want your users to select a folder, you'll have to make them point to a file inside that folder, and then at the server extract the folder name from the file name.

With normal HTML, you cannot retrieve a picture from a camera. Maybe if you write an ActiveX control, you could do it, but I haven't tried
anything like that before.

If you need help with the JavaScript solution, let me know.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

I'd prefer to get the picture directly from a camera than using the file browse. I'd also rather use javascript that activex, so if you have a solution for this I would be very interested in it!

Thank you!
Bob


Imar August 21st, 2004 01:53 AM

Unfortunately, with "JavaScript solution" I was referring to getting the file name from a file control, which I mentioned first in my post.

Getting a picture directly from a camera cannot be done with "regular Web languages" like HTML or JavaScript. You'll need to use other technologies like ActiveX or maybe Java.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

bleitner August 21st, 2004 09:47 AM

Quote:

quote:Originally posted by Imar
 Unfortunately, with "JavaScript solution" I was referring to getting the file name from a file control, which I mentioned first in my post.

Getting a picture directly from a camera cannot be done with "regular Web languages" like HTML or JavaScript. You'll need to use other technologies like ActiveX or maybe Java.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

Ok, that's what I was afraid of - I guess it's on to ActiveX. Thank you so much for your help :)

Bob



All times are GMT -4. The time now is 08:01 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.