donkey.ear-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jun-07 22:44 UTC
File Upload without page refresh
Im really not understanding somthing with Prorotype, what I want to do is call a piece of php that accepts a file from a form, process it and return a very simple true/false. Now Ive been playing with it inside of a form element and so far have this. <script type="text/javascript"> function addImage( form ) { var success = function(t) { alert( ''woohoo'' ); } new Ajax.Request( ''addImage.php'', { method: ''post'', asyncronous: false, contentType: ''multipart/form-data'', postBody: Form.serialize( form ), onComplete: success, // Handle 404 on404: function(t) { alert(''Error 404: location "'' + t.statusText + ''" was not found.''); }, // Handle other errors onFailure: function(t) { alert(''Error '' + t.status + '' -- '' + t.statusText); } } ); } </script> <form id=''test'' enctype="multipart/form-data" action='''' method=''post'' onsubmit="addImage( ''test'' ); return false;"> <input type="file" name="file" id="file"/> <input type="submit"/> </form> The script seams to suceed, not nothing ever reaches the PHP, what am I doing wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 08 Jun 2007, at 00:44, donkey.ear-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote:> Im really not understanding somthing with Prorotype, what I want to do > is call a piece of php that accepts a file from a form, process it and > return a very simple true/false. Now Ive been playing with it inside > of a form element and so far have this. > <form id=''test'' enctype="multipart/form-data" action='''' > method=''post'' onsubmit="addImage( ''test'' ); return false;"> > <input type="file" name="file" id="file"/> > <input type="submit"/> > </form> > > The script seams to suceed, not nothing ever reaches the PHP, what am > I doing wrong?This has been beaten to death already, but here we go again: you can''t upload files through ajax because of javascript security. You could use something like SWFUpload to mimic this behavior or use a hidden iframe. Just google it up and you''ll find plenty of resources on this matter? Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
donkey.ear-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jun-08 08:39 UTC
Re: File Upload without page refresh
Hmm SWF upload may not be feasible, but Im going to look into the hidden iframe idea, any further information appreciated. On Jun 8, 12:42 am, Peter De Berdt <peter.de.be...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> On 08 Jun 2007, at 00:44, donkey....-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote: > > > Im really not understanding somthing with Prorotype, what I want to do > > is call a piece of php that accepts a file from a form, process it and > > return a very simple true/false. Now Ive been playing with it inside > > of a form element and so far have this. > > <form id=''test'' enctype="multipart/form-data" action='''' > > method=''post'' onsubmit="addImage( ''test'' ); return false;"> > > <input type="file" name="file" id="file"/> > > <input type="submit"/> > > </form> > > > The script seams to suceed, not nothing ever reaches the PHP, what am > > I doing wrong? > > This has been beaten to death already, but here we go again: you > can''t upload files through ajax because of javascript security. You > could use something like SWFUpload to mimic this behavior or use a > hidden iframe. Just google it up and you''ll find plenty of resources > on this matter? > > Best regards > > Peter De Berdt--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
donkey.ear-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jun-08 10:27 UTC
Re: File Upload without page refresh
Okay for those people interested I have this now working, I''ll post something a bit later with the simplest example I can clobber together, thanks for the hint. I took inspiration from http://www.anyexample.com/programming/php/php_ajax_example__asynchronous_file_upload.xml The important bit which I missed was you target your form to the hidden iframe. <form action="script.php" target="upload_iframe" method="post" enctype="multipart/form-data"> <label for="file">text file uploader:</label><br> <input type="file" name="file" id="file"> </form> <iframe name="upload_iframe" style="width: 400px; height: 100px; display: none;"></iframe> Once I figured out how that worked it clicked On Jun 8, 9:39 am, "donkey....-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <donkey....-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hmm SWF upload may not be feasible, but Im going to look into the > hidden iframe idea, any further information appreciated. > > On Jun 8, 12:42 am, Peter De Berdt <peter.de.be...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote: > > > On 08 Jun 2007, at 00:44, donkey....-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote: > > > > Im really not understanding somthing with Prorotype, what I want to do > > > is call a piece of php that accepts a file from a form, process it and > > > return a very simple true/false. Now Ive been playing with it inside > > > of a form element and so far have this. > > > <form id=''test'' enctype="multipart/form-data" action='''' > > > method=''post'' onsubmit="addImage( ''test'' ); return false;"> > > > <input type="file" name="file" id="file"/> > > > <input type="submit"/> > > > </form> > > > > The script seams to suceed, not nothing ever reaches the PHP, what am > > > I doing wrong? > > > This has been beaten to death already, but here we go again: you > > can''t upload files through ajax because of javascript security. You > > could use something like SWFUpload to mimic this behavior or use a > > hidden iframe. Just google it up and you''ll find plenty of resources > > on this matter? > > > Best regards > > > Peter De Berdt--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---