2012-06-06 57 views
2

Air应用程序出现问题,并通过php将图像上传到服务器。 我做错了什么?进展一切正常,显示进展和反应,但PHP无法找到一个图像。上传AIR应用程序的图像

 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"); 
+0

如您所说的闪存部分工作(显示进度等),看到PHP文件将是有用的。 –

+0

我找到了解决方案。代码是正确的,问题在后端。但谢谢你的答案。 – goodm

+0

告诉别人什么是问题,以便他们可以避免你的错误。 –

回答

1

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

  1. 保存图像,你应该将图像转换为字节数组,
  2. 做任何一件编码过程(无论是PNGEncoding或JPEGEncoding)
  3. 如果你想那么做的任何标准编码(base64)为安全
  4. 然后将该字符串发送到php
  5. 让您的php文件读取该数据并写入它。
+0

谢谢,但案例很接近,我找到了解决办法,那不是我的错。 – goodm

+0

是的,我看到上面的评论。我发布该文章以帮助其他人搜索相同的内容。希望它可以提供一些关于使用PHP保存图像的想法。 – Moorthy