2

Air 应用程序出现问题并通过 php 将图像上传到服务器。我做错了什么?进展中一切正常,正在显示进展和响应,但 php 找不到图像。

        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");
4

1 回答 1

1

文件引用的上传无法向 php 文件发送任何请求或变量。它只是将文件上传到您在 url 中给出的路径。如果要使用 php 保存图像

  1. 您应该将图像转换为字节数组,
  2. 执行任何一个编码过程(PNGEncoding 或 JPEGEncoding),
  3. 如果您愿意,请执行任何标准编码(base64)以确保安全
  4. 然后将该字符串发送到 php
  5. 让您的 php 文件读取并写入该数据。
于 2012-09-11T12:00:40.907 回答