Hi All,
Been scratching my head for too long on this: Using jquery.form, (http://malsup.com/jquery/form) with PHP ... my $_FILES['someimage']
gets set but the error number is always UPLOAD_ERR_NO_FILE
, size is also 0.
The JavaScript:
$('form input[type=file]').change(function(){
$(this).clone().appendTo('#imgform');
$('#imgform').ajaxForm();
$('#imgform').ajaxSubmit(
{
type:'POST'
}
);
});
Which appends to:
<form id="imgform" method="POST" action="/api/images.php" enctype="multipart/form-data"></form>
From another form which has bog-standard file inputs.
PHP logs are clean, but var_dump
ing $_FILES always shows that the index is set to the name of the form element ... but no data.
Thanks guys! (Sorry, I know jQuery-like questions are too frequent round these parts).
EDIT I found http://stackoverflow.com/questions/415483/clone-a-file-input-element-in-javascript which contains further information and suggested alternatives.
What I decided to do is have a single form for non JavaScript browsers, and JavaScript/jQuery breaks the single form into three forms:
Head form -> File upload form -> tail form
Then I can post the file upload async, and when the tail's submit is clicked, glue the form together into a POST as they are just text fields.