In short, I want to get the filename of the file I just uploaded from inside an iFrame.
Let me start by telling you that I do have a more or less working ajax upload script (i.e suits my needs for now). It is very simple and goes as follows:
<form action='upload.php' method='post' enctype='multipart/form-data' target='upload_frame' id='create_file'>
<iframe id='upload_frame' name='upload_frame' src='' scrolling="no"></iframe>
<label>Title</label>
<input type='text' name='title'>
<label>File</label>
<input type='file' name='file'>
<button id='submit'>Upload</button>
</form>
I can 'include' this form by pressing a show-upload-form button so this form can be added to a page dynamically. Now when the submit button is clicked 'upload.php' will handle the upload and put the filename in the iFrame. Since I am the owner of the iFrame I tried using an echo with an ID in the upload.php (where $title is the 'cleaned' version of a given file).
echo <span id="file_path" path="uploads/'.$title.'">' . $title . '</span>'
(So after I upload my iframe would look like:
<iframe 'stuffinigs'>
<span id="file_path" path="uploads/somefile.png">somefile.png</span>
</iframe>
So I could get the file_path with the following submit functionality:
$('#submit').live('click', function() {
upload_form.find('form').attr('action', UPLOAD_SCRIPT_URL).submit();
var path = upload_form.find('iframe').contents().find('#file_path').attr('path');
/* I would like to do more actions with the path here */
return false; // So it can be used with multiple forms on the screen
});
So the upload works, but the path is undefined, which is pretty obvious as the file submit() and upload isn't instant. Now I thought about adding a small delay, but I couldn't get that to work either.
So, I am hoping there is some .submit(function(){ }); callback function (this is not the case for this version of submit(function(){}), but maybe there is some function or functionality of .submit() I do not know of).
So how can I get the #file_path path attribute (i.e the uploaded file path) from an iFrame, after a file has been uploaded.