MyBB Community Forums

Full Version: inline upload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm making an inline upload script using ajax and iframe.
I've made the ajax script and everything is done, although I got an problem since It runs the ajax script before the upload is done, and therefore the file that you just uploaded won't appear.
I've got this code here now.
<form enctype="multipart/form-data" method="post" action="admin.php?p=inline-upload" onsubmit="quickupload('admin.php?p=inline-upload');" target="iframe">
	<fieldset class="adminfield">
		<legend>&nbsp;Last opp fil&nbsp;</legend>
		<div style="margin-bottom: 10px">
			<input type="file" name="file" size="50" />
			<input type="hidden" name="url" value="$url" />
			<input type="submit" name="submit" value="Last opp fil" class="submit" />
		</div>
		<div id="loading" style="display: none;"></div>
		<div id="items">$files</div>
		<iframe name="iframe" src="admin.php?p=inline-upload" style="display:none;height:0;width:0"> </iframe>
	</fieldset>
</form>
You can see the jscript over Here
So it passes the uploading file to the iframe and what it should do is it should show the files in the items id.

The ajax returns this.
echo show_files();
which is an list over all files in an folder.

But the problem is as said that it runs before the file is uploaded, any ideas?

I know I could give it an timeout but.. I wouldn't know if the page was done loading or not :/
Sorry for bumping this one, no body know? I really need this.
Will be in great thanks to the one that helps me, if you want more we can probably work something out.
Can you post all the scripts and how to install them?
Well that did take a while since I'm using it on my admin panel.
Using alot of classes and such.
And I don't wanna post all off it so I stripped it down, not the way I would do it normally of course.
Anyways. here you go.

Upload it to your ftp server and change the chmod of the upload folder to make it writeable, then point your browser to the adresse and try uploading, you'll see it change to "Upload finished.." and then it starts to make the request to the file.
You should be able to do it without using AJAX at all but using remote scripting with the IFRAME. This also means one less call to the server - so overall it'll be quicker.

http://developer.apple.com/internet/webc...frame.html

I don't have time to whip up a complete example but see the attached file for the basics of how my implementation would look..

You can try it at http://www.surfionline.com/temp/index.php however it won't write any files to the server.
Thank you Chris! I'm trying this out now, haven't figured it out yet but you got me on the right path at least. Thank you Smile
I got it working, sort off, thanks again.
Only thing now is that there is an problem with inserting it now, probably an problem with quotes. I can't find it out though.
So here is an dump from the iframe. Hope someone can help me.
<script type="text/javascript">window.onload = function() { window.parent.handle_response("Ferdig lastet....", '&raquo;&nbsp;<a href="#" onclick="insert(\'./upload/IMGP1174.JPG\', 1); return false;">IMGP1174.JPG</a> - 547 KB - <a href="./admin.php?p=delete&file=IMGP1174.JPG">Slett</a><br />
'); };</script>

This code works though:
<script type="text/javascript">window.onload = function() { window.parent.handle_response("Ferdig lastet....", 'test'); };</script>

Sorry but my javascript skills are well bad.
Thanks for all the help. I've found out an way todo it now, probably not the best but it works. Thanks again Smile