1 Reply Latest reply on Apr 11, 2007 3:47 AM by Newsgroup_User

    Uploading images Problem

    Philip C
      hi!

      I want to be able to upload an image to my server. I have just tried the example in the Flash help (see below)
      All seem to work fine, and I get no errors (in case I dont try to upload to a non exixting folder on the server or so).
      And when uploading is completed tie file is not there on the server??? I have tried to upload it to my machine (is running apache, php and mySQL, the versions you get with PHPHome edition) , I have also tried with the server I use for my webhosting.

      As I said, it all seem to work fine, the only problem is that the file do not show up on the server afterwards.

      any Ideas???

      the example I used:

      // http://localhost/


      import flash.net.FileReference;

      var allTypes:Array = new Array();
      var imageTypes:Object = new Object();
      imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
      imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
      allTypes.push(imageTypes);

      var listener:Object = new Object();

      listener.onSelect = function(file:FileReference):Void {
      apan_mc.text +="onSelect: " + file.name;
      if(!file.upload("The URL to the server Im using, have both tried localy and on my webhosting server")) {
      apan_mc.text +=newline + "Upload dialog failed to open.";
      }
      if(file.upload("The URL to the server Im using, have both tried localy and on my webhosting server")){
      apan_mc.text +=newline + "Le konkarong";
      }
      }

      listener.onCancel = function(file:FileReference):Void {
      apan_mc.text +="onCancel";
      }

      listener.onOpen = function(file:FileReference):Void {
      apan_mc.text +=newline +"onOpen: " + file.name;
      }

      listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
      apan2_mc.text ="onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal;
      }

      listener.onComplete = function(file:FileReference):Void {
      apan_mc.text +=newline +"onComplete: " + file.name;
      }

      listener.onHTTPError = function(file:FileReference):Void {
      apan_mc.text +=newline +"onHTTPError: " + file.name;
      }

      listener.onIOError = function(file:FileReference):Void {
      apan_mc.text +=newline +"onIOError: " + file.name;
      }

      listener.onSecurityError = function(file:FileReference, errorString:String):Void {
      apan_mc.text +=newline +"onSecurityError: " + file.name + " errorString: " + errorString;
      }

      var fileRef:FileReference = new FileReference();
      fileRef.addListener(listener);
      fileRef.browse(allTypes);
        • 1. Re: Uploading images Problem
          Level 7
          Philip C wrote:
          > hi!
          >
          > I want to be able to upload an image to my server. I have just tried the
          > example in the Flash help (see below)
          > All seem to work fine, and I get no errors (in case I dont try to upload to a
          > non exixting folder on the server or so).
          > And when uploading is completed tie file is not there on the server??? I have
          > tried to upload it to my machine (is running apache, php and mySQL, the
          > versions you get with PHPHome edition) , I have also tried with the server I
          > use for my webhosting.
          >
          > As I said, it all seem to work fine, the only problem is that the file do not
          > show up on the server afterwards.
          >
          > any Ideas???

          Hi Philip C,

          As you don't mention any PHP scripts I suspect that by default you
          aren't moving the file once it is uploaded to the server via PHP. By
          default PHP will upload a file to it's default upload directory. However
          once the procedure has completed it deletes it as this folder is only
          temporary. Therefore if you don't move it, your file will disappear.

          This PHP example script illustrates how to move it to another directory
          on the server.

          The script below is for a component (FTConnector) I created that does
          File uploading (based on FileReference / FileReferenceList), but
          FileReference will work the same way. If you are interested in the
          component you can download from the downloads section on my blog:
          http://blog.flashgen.com/downloads/

          <?php
          /*
          Please note:
          This file is for testing only under no circumstances should it be
          placed on any
          mission critical machines as the following script can easily be
          bypassed by those
          with less than honorable intentions.

          To use this test file you will need to place it on your testing
          webserver in the
          server root or deeper. You will also need to create a folder called
          'uploads'
          at the same level.

          One thing to note is that when the FileTransferConnector connects to
          this script
          the FileReference class identifies the object it is posting by calling
          it 'Filedata'. This cannot be
          altered so make sure your scripts are updated to reflect this.
          */
          $target_path = "uploads/";

          $target_path = $target_path . basename( $_FILES["Filedata"]["name"]);

          move_uploaded_file($_FILES["Filedata"]["tmp_name"], $target_path);
          ?>

          I don't have Flash open at the moment so I cannot test your AS code, but
          it looks like the example code in the help docs so it should, as you
          have mentioned, work OK.

          I could be barking up the wrong tree, but then again :p

          --
          regs
          m

          ------------------------------------
          Mike Jones
          FlashGen.Com
          ------------------------------------
          w./ www.flashgen.com
          e./ forum_postsATflashgenDOTcom
          b./ blog.flashgen.com
          ------------------------------------