views:

143

answers:

3

NOTE: The issue was resolved, I was apparently editing the wrong file. Silly me. Thanks

I am using an image upload script that posts file to the a PHP script that then saves the file to the server. Here is the upload form:

  <form action="upload.php" method="post" name="image_upload" id="image_upload" enctype="multipart/form-data">
    <input type="hidden" name="forumuser" value="testname" />
    <input type="hidden" name="email" value="[email protected]" />
    <input type="file" size="25" name="uploadfile" id="uploadfile" class="file margin_5_0" onchange="ajaxUpload(this.form);" />
 </form>

There is no submit as it is done through an AJAX call. The image is received and uploaded to the server, but my PHP script fails to actually receive any POST variables:

$forumuser = $_POST['forumuser'];
$email = $_POST['email'];

Echo'ing these variables result in nothing. This is likely do to the enctype, as I have found people who switched it have found that the POST variables will work but the file upload does not. None of the solutions in the PHP bug report have worked for me.

Here are some settings in the ajax.js file:

 form.setAttribute("target","uploadform-temp");
 form.setAttribute("action",get_url);
 form.setAttribute("method","post");
 form.setAttribute("enctype","multipart/form-data");
 form.setAttribute("encoding","multipart/form-data");

I appreciate any assistance.

+1  A: 

AJAX can't do multipart/form-data encoded requests, only application/x-www-form-urlencoded.

This is a limitation of the XmlHttpRequest API. The only workaround is to use an iframe, the technique for which is just a google search away.

Peter Bailey
Well the file upload works through the AJAX submission, so I'm not sure that is the case.
Josh
you can use javascript to activate the upload but you cant use ajax to actually send the file.
RobertPitt
Yes Robert is correct, it just activates the submission =)
Josh
+1  A: 

I'm light on AJAX, but if values are being passed you can get them from $HTTP_RAW_POST_DATA.

I believe $_POST only gets filled with encrypt = "application/x-www-form-urlencoded"

http://php.net/manual/en/reserved.variables.httprawpostdata.php

rxn
i think your wrong with that, `enctype` just tells the server what encoding the data is being sent as, should have no effect on how php places the data in the globals.
RobertPitt
I echo'ed $HTTP_RAW_POST_DATA back through the AJAX reply, and it was empty =(
Josh
+1  A: 

Alternatively to using iframes, you can use a Flash-based uploader such as FancyUpload that integrates nicely with AJAX applications and can even show a progress bar.

Archimedix
I'd rather not use Flash, as I am trying to integrate this into forum user accounts, which is why I need to pass the extra POST variables. Thanks though =)
Josh