【问题标题】:Convert Photo Upload API from .Net C# into PHP将照片上传 API 从 .Net C# 转换为 PHP
【发布时间】:2012-02-26 03:38:04
【问题描述】:

我目前正在使用 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))
        }
    }
}

【问题讨论】:

  • 是的,有可能。我建议您尝试一下,如果遇到问题,请回到这里寻求帮助。您可以在 Internet 上找到许多 PHP 教程。

标签: c# php .net upload photo


【解决方案1】:
$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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    • 2018-03-27
    • 2015-05-15
    • 2012-07-05
    • 1970-01-01
    • 2018-10-14
    相关资源
    最近更新 更多