1 Reply Latest reply on Jan 12, 2011 7:07 AM by saisri2k2

    How to receive a file Stream from a php script

    flexillu10

      My php script outputs bytes of data from a selected adobe illustrator file...What do i need to do in my flex/air app to read the incoming bytes and write them to disk? Code is greatly appreciated.

       

      My php script similar to this

       

      <?php
      
      // ASSUME $result IS A RETURNED ARRAY REPRESENTING YOUR DATABASE
      // QUERTY SELECTING THE FILE THE USER WANTS TO DOWNLOAD
      
      // Send Content information to tell browser we're downloading a file and of what size the file is
      header( "Content-type: " . $result['ImageMIMEType'] );
      header( "Content-Disposition: attachment; filename=\"" . $result['ImageOriginalFileName'] . "." . $result['ImageOriginalFileExtension'] . "\"" );
      header( "Content-length: " . $result['ImageFileSize'] );
      
      // ALTERNATIVELY, IF YOU DIDN'T STORE ImageFileSize IN THE DATABASE YOU CAN USE:
      //header( "Content-length: " . filesize( "/path/to/images/" . $result['ImageFileName'] . "." . $result['ImageFileExtension'] ) );
      
      // In case the image is updated we don't want to cache the file
      header( "Cache-control: private" );
      
      $fp = fopen( "/path/to/images/" . $result['ImageFileName'] . "." . $result['ImageFileExtension'], "r" );
      
      // While we haven't reach the end of the file, print 2048 bytes of data from the file
      while( !feof( $fp ) ){
          $buffer = fread( $fp, 2048 );
          echo( $buffer );
      }
      
      // Once we're done, close the file
      fclose( $fp );
      
      ?>