将照片上传API从.Net C#转换为PHP


Convert Photo Upload API from .Net C# into PHP

我目前正在使用Redfoundry.com Framework(RFML)构建一个照片上传应用程序。不幸的是,他们给了我一个后端应该是什么样子的例子,在.Net 中

是否可以将这些代码转换为PHP?感谢您的帮助

编辑:格式为.jpg

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace MYNamespace
{
    public class api : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
              string res = "";
              if (context.Request.Files != null)
              {
                    if (context.Request.Files.Count > 0)
                     {
                            HttpPostedFile oHttpPostedFile = context.Request.Files[0];
                            if (oHttpPostedFile != null)
                            {
                                  if (oHttpPostedFile.ContentLength > 0)
                                  {
                                          oHttpPostedFile.SaveAs(System.IO.Path.Combine(System.Web.HttpContext.Current.Request.MapPath(@"PHOTOS"), guid + ".jpg"));
                                          res = "<results>SUCCESS</results>";
                                  }
                            }
                      }
               }
               context.Response.ContentType = "text/xml";
               context.Response.Write((res.length == 0 ? "<results>FAILED</results>" : res))
        }
    }
}
$return = '<results>FAILED</results>';
if ( 0 == $_FILES['file']['error'] && 'image/jpeg' == $_FILES['file']['type'] = )
{
   $temp_file = $_FILES['file']['tmp_name'];
   $destination_file = 'uplaod_dir/' . rand(1, 10000) . '.jpg';// you can change file as you want 
   if ( move_uploaded_file($temp_file, $destination_file) )
   {
       $return = '<results>SUCCESS</results>';    
   }
}
header ("Content-Type:text/xml");  
print $return;
exit;