4 Replies Latest reply on Oct 19, 2006 12:25 AM by valerioV

    Help me, upload file with PHP

    cubum
      How to upload file with PHP?example?. Please help me.
        • 1. Re: Help me, upload file with PHP
          valerioV
          I got the same problem. In my flex application I want to upload a file.
          I use a fileReference obj, here my flex code:

          private var fileRef:FileReference;

          private function tmpClick(event:Event){
          fileRef = new FileReference();
          fileRef.addEventListener(Event.SELECT, selectHandler);
          fileRef.addEventListener(Event.COMPLETE, completeHandler);
          fileRef.browse();
          }

          private function selectHandler(event:Event):void {
          var params:URLVariables = new URLVariables();
          var request1:URLRequest = new URLRequest(" http://localhost:8086/flex2/interf1/upload.php");
          request1.method = URLRequestMethod.POST;
          fileRef.upload(request);
          }

          The request is send to a "upload.php" script that print a selected file name in a text file:
          <?php

          $save_path = $_ENV['DOCUMENT_ROOT'];
          $file = $_FILES['Filedata'];
          $risultato = "FileName= ".$file['name']."\r\n";
          $fp = fopen($save_path."\out.txt", "w");
          fwrite($fp, $risultato);
          fclose($fp);
          ?>

          But the script isn't able to read the retrieved request data. Why? There's some mistake on the code?

          Thanks
          Valerio
          • 2. Re: Help me, upload file with PHP
            leotemp Level 1
            make sure you server side script works 100% first, build a simple HTML form that executes to it and confirm that your php is working as it should.
            • 3. Re: Help me, upload file with PHP
              valerioV Level 1
              Yes, my server Apache recognize the php scripts. I tried with a simple form, and it works fine.
              In my Tomcat I have configured my WEB-INF/web.xml in WEB-INF like this:

              - <servlet>
              <servlet-name>php</servlet-name>
              <servlet-class>net.php.servlet</servlet-class>
              </servlet>
              - <servlet>
              <servlet-name>php-formatter</servlet-name>
              <servlet-class>net.php.formatter</servlet-class>
              </servlet>
              - <servlet-mapping>
              <servlet-name>php</servlet-name>
              <url-pattern>*.php</url-pattern>
              </servlet-mapping>
              - <servlet-mapping>
              <servlet-name>php-formatter</servlet-name>
              <url-pattern>*.phps</url-pattern>
              </servlet-mapping>

              and I have added the phpsrvlt.jar file in WEB-INF/lib (with the files 'reflect.properties' and 'servlet.properties' that point at php5servlet.dll).
              There's some configuration more to do? Or is just a curse on me?

              Thanks
              Valerio
              • 4. Re: Help me, upload file with PHP
                valerioV Level 1
                Yes, my server Apache recognize the php scripts. I tried with a simple form, and it works fine.
                In my Tomcat I have configured my WEB-INF/web.xml in WEB-INF like this:

                - <servlet>
                <servlet-name>php</servlet-name>
                <servlet-class>net.php.servlet</servlet-class>
                </servlet>
                - <servlet>
                <servlet-name>php-formatter</servlet-name>
                <servlet-class>net.php.formatter</servlet-class>
                </servlet>
                - <servlet-mapping>
                <servlet-name>php</servlet-name>
                <url-pattern>*.php</url-pattern>
                </servlet-mapping>
                - <servlet-mapping>
                <servlet-name>php-formatter</servlet-name>
                <url-pattern>*.phps</url-pattern>
                </servlet-mapping>

                and I have added the phpsrvlt.jar file in WEB-INF/lib (with the files 'reflect.properties' and 'servlet.properties' that point at php5servlet.dll).
                There's some configuration more to do? Or is just a curse on me?

                Thanks
                Valerio