I am using the iframe technique to upload a file contained in a form.
It’s working perfectly, I even send myself an email with the file. The only problem is that I want to get infos from the iframe, such as file size. However, I can’t update the iframe’s content from the php script. I tried putting ‘echos’ on the line before it sends the email (so it actually gets there), but as soon as the iframe’s jQuery’s “load” function fires, there is nothing in the iframe. Even tried “Inspect element” and “view source”, all empty.
Am I missing something obvious? I can’t find anyone with the same problem on SO or google.
FORM:
<form id="submitResumeForm" method="post" enctype="multipart/form-data" action="career/sendResume" target="submitTarget">
<!-- input fields, etc -->
<input type="button" onClick="submitForm()" value="<?=lang('submit')?>" />
</form>
<iframe id="submitTarget" name="submitTarget" src="" style="position:absolute;top:-1000px;left:-1000px;width:0;height:0;border:0px solid #fff;"></iframe>
JAVASCRIPT:
function submitForm()
{
$('#submitResumeForm').attr('target', 'submitTarget');
// ... verifications ...
$('#submitTarget').load(function()
{
console.log( $(this).html() ); // Content is: "content before"
console.log( $(this).contents() ); //Garbage
});
// Line Below puts content in the iframe, and that content is still there after
// the php is executed, so iframe is NEVER updated
$('#submitTarget').html('content before');
$("#submitResumeForm").submit();
}
PHP CONTROLLER:
function sendResume()
{
echo 'ASDFASDFASDFASDF';
$this->load->library('email');
$this->email->clear();
$this->email->to($this->input->post('email'));
// ... other fields, attach file (working perfectly)
$this->email->send();
}
Here’s the solution:
The line
Is NOT updated in the DOM for some reason I don’t know, you have to use this if this ever happens to you: