8 Replies Latest reply on Dec 29, 2008 8:01 AM by W0utR

    accessing a php script

    W0utR Level 1
      Hi, i created a small application that lets me upload files to my server.
      I tested it on my localhost wich was working perfect.

      But when i upload the file to my server it doesnt work anymore.
      Do i have to do something special on my php file or on my flash app?
        • 1. Re: accessing a php script
          Damon Edwards Level 3
          Is the URL to the php file correct? Are you seeing any errors? What do you classify as "doesn't work anymore".
          • 2. Re: accessing a php script
            W0utR Level 1
            I'm pretty sure the url is correct, i checked it about 10 times, copied the url to the browser and it works

            I also added a few eventListeners to my file:
            file.addEventListener(Event.COMPLETE, fileCompleteHandler);
            file.addEventListener(ProgressEvent.PROGRESS, fileProgressHandler);
            file.addEventListener(IOErrorEvent.IO_ERROR, fileErrorHandler);

            When i test it on my localhost, the "fileCompleteHandler" is triggerd, but when i test de file online, the "fileErrorHandler" is triggerd


            Normally it's suposed to upload a picture i drag into the application, works offline, but online it doesn't work
            • 3. Re: accessing a php script
              Damon Edwards Level 3
              Make sure the url to the php file is based on your web server, and not your local file system, ie, "file:///C:". It needs to be http.
              • 4. accessing a php script
                W0utR Level 1
                I've checked that like 20 times

                this is my request url:
                var request:URLRequest = new URLRequest(' http://upload.woutr.be/upload.php');

                When you go to that file, u can see it is on my webserver, it's the same file i use on my localhost, wich works perfectly.

                This is the piece i use for uploading the file:
                quote:

                function uploadHandler(event:MouseEvent):void
                {
                var file:FileReference = FileReference(fileArr[0]);

                file.addEventListener(Event.COMPLETE, fileCompleteHandler);
                file.addEventListener(ProgressEvent.PROGRESS, fileProgressHandler);
                file.addEventListener(IOErrorEvent.IO_ERROR, fileErrorHandler);

                //var request:URLRequest = new URLRequest(' http://localhost:8888/upload.woutr.be/upload.php');
                var request:URLRequest = new URLRequest(' http://upload.woutr.be/upload.php');

                variables = new URLVariables;

                request.method = URLRequestMethod.POST;

                variables.randomPass = "password";
                request.data = variables;

                // if the checkbox is selected, choose a randomname
                if(randomName.selected == false)
                {
                variables.name = fileArr[0].name;
                }
                else
                {
                var date:Date = new Date();
                variables.name = date.getSeconds() + date.getMilliseconds() + date.getMinutes() + Math.round(Math.random() * 99999999999) + "." + fileArr[0].extension;
                }

                // upload the file
                file.upload(request);
                }
                function fileCompleteHandler(event:Event):void
                {
                uploadBtn.removeEventListener(MouseEvent.CLICK, uploadHandler);
                copyBtn.addEventListener(MouseEvent.CLICK, copyClickHandler);
                urlTxt.text = " http://dump.woutr.be/" + variables.name;
                }
                function fileProgressHandler(event:ProgressEvent):void
                {
                urlTxt.text = "Uploading the file";
                }
                function fileErrorHandler(event:IOErrorEvent):void
                {
                urlTxt.text = "Error uploading the file";
                }

                • 5. Re: accessing a php script
                  Damon Edwards Level 3
                  Try declaring your variables outside the functions, like so: (if you run the below, what is output into the output panel?)

                  var file:FileReference;
                  var request:URLRequest;
                  function uploadHandler(event:MouseEvent):void {
                  file=FileReference(fileArr[0]);
                  file.addEventListener(Event.COMPLETE, fileCompleteHandler);
                  file.addEventListener(ProgressEvent.PROGRESS, fileProgressHandler);
                  file.addEventListener(IOErrorEvent.IO_ERROR, fileErrorHandler);
                  request=new URLRequest(' http://upload.woutr.be/upload.php');
                  variables=new URLVariables ;
                  request.method=URLRequestMethod.POST;
                  variables.randomPass="password";
                  request.data=variables;
                  if (randomName.selected==false) {
                  variables.name=fileArr[0].name;
                  } else {
                  var date:Date = new Date();
                  variables.name=date.getSeconds()+date.getMilliseconds()+date.getMinutes()+Math.round(Math .random()*99999999999)+"."+fileArr[0].extension;
                  }
                  trace(request.url);
                  file.upload(request);
                  }
                  function fileCompleteHandler(event:Event):void {
                  uploadBtn.removeEventListener(MouseEvent.CLICK, uploadHandler);
                  copyBtn.addEventListener(MouseEvent.CLICK, copyClickHandler);
                  urlTxt.text=" http://dump.woutr.be/"+variables.name;
                  }
                  function fileProgressHandler(event:ProgressEvent):void {
                  urlTxt.text="Uploading the file";
                  }
                  function fileErrorHandler(event:IOErrorEvent):void {
                  urlTxt.text= event.toString();
                  }
                  • 6. accessing a php script
                    W0utR Level 1
                    Hi, thank you for your reply.

                    The output i get is the following:
                    [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error. URL: http://upload.woutr.be/upload.php" errorID=2038]


                    and the request.url = http://upload.woutr.be/upload.php
                    • 7. Re: accessing a php script
                      Damon Edwards Level 3
                      then there is an error in your script that is causing the file to fail to upload. make sure there are no path errors, and that any folders/files you're writing to are chmod to 777
                      • 8. Re: accessing a php script
                        W0utR Level 1
                        but the IOErrorEvent was trigged, doesn't that not mean that he can't load the file?

                        Because i double checked everyting, the paths to the folder, to the upload script.
                        Everything seems right, i also added the chmod 777 to the folder