2

Have an issue with Air application and upload the image to server by php. What I'm doing wrong? On progress everything is alright, is showing progress and response, but php can't find an image.

        var request:URLRequest = new URLRequest("http://xxxxxxxxxx/api.php");           
        request.method = URLRequestMethod.POST;
        request.contentType = "application/octet-stream";
        var variables:URLVariables = new URLVariables();  
        variables.action = "addEntry";  
        variables.user = "1";
        request.data = variables; 

        var file:FileReference = new FileReference();           
        var filenameSmall:String = "xxxxx/" + _userName+"/thumbnail.jpg";
        if(_fb == true)
        {
            filenameSmall = "xxxxx/" + user +"/thumbnail.jpg";
        }
        file = File.desktopDirectory.resolvePath( filenameSmall );
        file.addEventListener(ProgressEvent.PROGRESS, uploadProgress);
        file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadDataComplete);
        file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, uploadError);
        file.addEventListener(HTTPStatusEvent.HTTP_STATUS, uploadError); 
        file.addEventListener(IOErrorEvent.IO_ERROR, uploadError);
        file.upload(request, "image");
goodm
  • 7,275
  • 6
  • 31
  • 55

1 Answers1

1

The upload of file reference could not send any request or variables to php files. It just upload the file to the path you have given in the url. If you want to save an image using php

  1. you should convert the image to byte array,
  2. Do any one the encoding process(either PNGEncoding or JPEGEncoding),
  3. If you want then do any standard encoding(base64) for security
  4. Then send that string to php
  5. Make your php file to read that data and write it.
Moorthy
  • 754
  • 3
  • 6
  • Thanks, but case is close, I found the solution, what wasn't my fault. – goodm Sep 11 '12 at 17:30
  • yes I saw the comments above. I post that to help somebody else searching the same. Hope it might give some idea about saving image using php. – Moorthy Sep 12 '12 at 04:26