Jump to content

posting mutlidimensional array with ajax and php


transformer

Recommended Posts

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

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.