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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.