In need of expert advice regarding javascript file upload

A

andyau

I am developing a google maps mash up.
I have a form in the infowindow (information bubble that pops up) what
I would like to do offer users the ability to upload a file from
inside this window.

At present there is a html form which when submitted it's content is
sent via javascript to a php script to insert into my mysql database.

Here is my problem is it possible to pass the multipart information
that is the file upload through javascript to the php?

The current dev site can be found here http://www.streetartlocator.com/dev/add_location.php

Any help will be much appreciated.

Regards
Andy Clark
 
V

VK

I am developing a google maps mash up.
I have a form in the infowindow (information bubble that pops up) what
I would like to do offer users the ability to upload a file from
inside this window.

At present there is a html form which when submitted it's content is
sent via javascript to a php script to insert into my mysql database.

Here is my problem is it possible to pass the multipart information
that is the file upload through javascript to the php?

No. XMLHttpRequest doesn't allow to access local file system, so you
are only able to send file name, but not the file content.

For AJAX-like file upload - so user stays on the same page after form
submission - you are using hidden iframe with form target attribute
pointing to that frame name.

<form
name="form01"
enctype="multipart/form-data"
action="http://www.example.com/cgi-bin/etc"
target="dumpster">
<input type="file" name="file01">
<!-- etc. -->
</form>

<iframe
name="dumpster"
src="blank.html"
style="display:none !important"></iframe>

and the like.
 
V

VK

XMLHttpRequest doesn't allow to access local file system, so you
are only able to send file name, but not the file content.

For AJAX-like file upload - so user stays on the same page after form
submission - you are using hidden iframe with form target attribute
pointing to that frame name.

<form
name="form01"
enctype="multipart/form-data"
action="http://www.example.com/cgi-bin/etc"
target="dumpster">
<input type="file" name="file01">
<!-- etc. -->
</form>

<iframe
name="dumpster"
src="blank.html"
style="display:none !important"></iframe>

and the like.

It is the most commonly used way if one needs server-side feedback
about the performed operation, normally a HTML page with onload script
in it to inform the mother page that the operation is completed.

If you don't need any feedback unless server-side error occured, then
you may use a regular multipart/form-data form w/o target and iframe.
In such case just return 204 No Content response from your server.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top