Jump to content

AJAX - PHP - & client upload


george

Recommended Posts

I have been using AJAX to send and retrieve data to my webpages, and all was fine until I discovered that I needed to upload files from the browser as well as field content. So I discovered the php way of doing this, which entails using the

	<form enctype="multipart/form-data" action="popreceipts.php" method="post" >		<input type="hidden" name="MAX_FILE_SIZE" value="300000" />Send this file: <input name="userfile" type="file" />		<input type="submit" value="Send File" />	</form>

The problem is, this forces a page reload. Isn’t there an AJAX way to get the form “file” data to the php program on the server? I only see

	xmlHttp=GetXmlHttpObject();	xmlHttp.onreadystatechange=invosent;	xmlHttp.open('POST','popreceipts.php',true);	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	xmlHttp.setRequestHeader("enctype", "multipart/form-data");	xmlHttp.setRequestHeader("Content-Length", param.length);	xmlHttp.send(param);

or the GET method. I’m sure there must be a way to upload a file from a web browser without having to reload the page. I just don’t know what it is yet.

Link to comment
Share on other sites

I’m sure there must be a way to upload a file from a web browser without having to reload the page.
Why do you think that?There's not a way to do that. The file needs to be sent to the server. The browser sends the file to the server when it makes a request. If you stop the browser from sending a request (which is what happens when the page reloads), then the file won't get sent. Javascript is not able to just get a file from the user's computer and send it to the server, if it could do that then we would have major security problems.
Link to comment
Share on other sites

Why do you think that?
Because it felt good? I got the whole web app going from input screen to input screen, without ever reloading a page. Now I have to figure out how to reload and get back to where I was. Thanks for the info. Now I won't be spending the day trying to do the impossible.
Link to comment
Share on other sites

Because it felt good?
Yeah I hear you. Sometimes I like to think that the rest of the world wants to invite America over for tea and that our president can read at a fourth grade level. But yeah, sadly reality gets in the way. But it's a good thing that Javascript can't send out your files, or else ActiveX probably wouldn't be the main attack vector for online malware.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...