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

将照片上载API从.Net C#转换为PHP,c#,php,.net,upload,photo,C#,Php,.net,Upload,Photo,我目前正在使用Redfoundry.com框架(RFML)构建一个照片上传应用程序。不幸的是,在.Net中,他们给了我一个后端应该是什么样子的示例 甚至可以将此代码转换为PHP吗?谢谢你的帮助 编辑:格式为.jpg using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; namespace MYNamespace { public class

我目前正在使用Redfoundry.com框架(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))
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.IO;
名称空间MYNamespace
{
公共类api:IHttpHandler
{
公共void ProcessRequest(HttpContext上下文)
{
字符串res=“”;
if(context.Request.Files!=null)
{
如果(context.Request.Files.Count>0)
{
HttpPostedFile oHttpPostedFile=context.Request.Files[0];
if(oHttpPostedFile!=null)
{
如果(oHttpPostedFile.ContentLength>0)
{
OhttpostedFile.SaveAs(System.IO.Path.Combine(System.Web.HttpContext.Current.Request.MapPath(@“PHOTOS”),guid+“.jpg”);
res=“成功”;
}
}
}
}
context.Response.ContentType=“text/xml”;
context.Response.Write((res.length==0?“失败”:res))
}
}
}
$return='FAILED';
如果(0=$\u文件['file']['error']&&&'image/jpeg'=$\u文件['file']['type']=)
{
$temp_file=$_FILES['file']['tmp_name'];
$destination_file='uplaod_dir/'.rand(11000)。'.jpg';//您可以根据需要更改文件
如果(移动上传的文件($temp文件,$destination文件))
{
$return='SUCCESS';
}
}
标题(“内容类型:text/xml”);
打印$return;
出口

是的,这是可能的。我建议您尝试一下,如果您遇到问题,请回来寻求帮助。您可以在internet上找到许多PHP教程。
$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;