transformer Posted May 20, 2008 Share Posted May 20, 2008 im not sure if this is more of an ajax question than php but maybe someone will have come across this issue before; im using ajax and php to upload an array of images to a mysql database. when i just submit the form to a php page it works a treat and i can simply retrieve the array from the client using $_FILES[ARRAY][ELEMENT] however i want to submit via ajax. Can anyone with experience give me some guidance Quote Link to comment Share on other sites More sharing options...
tomfmason Posted May 20, 2008 Share Posted May 20, 2008 im not sure if this is more of an ajax question than php but maybe someone will have come across this issue before; im using ajax and php to upload an array of images to a mysql database. when i just submit the form to a php page it works a treat and i can simply retrieve the array from the client using $_FILES[ARRAY][ELEMENT] however i want to submit via ajax. Can anyone with experience give me some guidance You can't upload via ajax. There is however another way that you could do it and have the feel of an ajax upload. You can use an iframe and a target in your form like this: <form action="your_ajax_upload_script.php" target="your_iframe"></form <iframe name="your_iframe" id="your_iframe"></iframe> Then in your upload script you could do something like the following. note this is a very simple example showing how to notifiy the parent page of the file upload. In this example I will not cover any of the php fileupload basics. <script type="javascript"> <?php //this is just an example. $uploaded represents the success or failure of the upload files. if($uploaded){ echo "parent.alert('The files were uploaded');"; } else { echo "parent.alert('The files were not uploaded');"; } ?> </script> That is a very simple example but I hope it helps. Good luck, Tom Quote Link to comment Share on other sites More sharing options...
transformer Posted May 20, 2008 Author Share Posted May 20, 2008 thats great thanks, the iframe is a bit ugly but im sure i can possible hide Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 20, 2008 Share Posted May 20, 2008 I've used this in the past...does all the IFRAME stuff for you: http://www.webtoolkit.info/ajax-file-upload.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.