On 4 déc, 20:08, JohnofLong <[EMAIL PROTECTED]> wrote:
> I am having issues with my GWT application being able to upload
> images. My html form and PHP file work fine but when I try and upload
> an image with my GWT app and my PHP file it does not work and I get a
> null response.
[...]
>             form.setAction("http://www.myurl.com/phpwrite/upload.php";);
[...]
>         form.addFormHandler(new FormHandler() {
>         public void onSubmitComplete(FormSubmitCompleteEvent event) {
>                 Window.alert(event.getResults());
>         }
>                 public void onSubmit(FormSubmitEvent event) {
>
>                 }
>         });

If your GWT app isn't itself running from http://www.myurl.com, then
you'll face the Same-Origin Policy which will prevent you from reading
the server response's content, and event.getResults() will be null.

That's explained in the JavaDoc (in the "Tip" subsection):
http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/FormSubmitCompleteEvent.html#getResults()

>     // Add image and button to the RootPanel
>     RootPanel.get().add(form);
>   }
>   private boolean isValidFileName() {
>           String fn = fileName.getText();
>           Window.alert(fn);
>           if(fn.contains(".")) {
>                   Window.alert("Not a valid file name no extensions 
> required");
>                   return false;
>           }
>           else {
>                   return true;
>           }
>   }
>
> }
>
> PHP Code
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1" />
> </head>
>
> <body>
>
> <?php
> // Where the file is going to be placed
> $target_path = "files/";
>
> /* Add the original filename to our target path.
> Result is "uploads/filename.extension" */
> $target_path = $target_path . basename( $_FILES['uploadedfile']
> ['name']);
>
> $target_path = "files/";
>
> $target_path = $target_path . basename( $_FILES['uploadedfile']
> ['name']);
>
> if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
> $target_path)) {
>     echo "The file ".  basename( $_FILES['uploadedfile']['name']).
>     " has been uploaded";} else{
>
>     echo "There was an error uploading the file, please try again!";}
>
> ?>
>
> </body>
> </html>
>
> HTML Form:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1" />
> </head>
>
> <body>
>
> <form enctype="multipart/form-data" action="uploader.php"
> method="POST">
> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
> Choose a file to upload: <input name="uploadedfile" type="file" /><br /
>
> <input type="submit" value="Upload File" />
> </form>
>
> </body>
> </html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to