Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.67 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Convert Photo Upload API from .Net C# into PHP
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.IO;
  7. namespace MYNamespace
  8. {
  9.     public class api : IHttpHandler
  10.     {
  11.         public void ProcessRequest(HttpContext context)
  12.         {
  13.               string res = "";
  14.               if (context.Request.Files != null)
  15.               {
  16.                     if (context.Request.Files.Count > 0)
  17.                      {
  18.                             HttpPostedFile oHttpPostedFile = context.Request.Files[0];
  19.                             if (oHttpPostedFile != null)
  20.                             {
  21.                                   if (oHttpPostedFile.ContentLength > 0)
  22.                                   {
  23.                                           oHttpPostedFile.SaveAs(System.IO.Path.Combine(System.Web.HttpContext.Current.Request.MapPath(@"PHOTOS"), guid + ".jpg"));
  24.                                           res = "<results>SUCCESS</results>";
  25.                                   }
  26.                             }
  27.                       }
  28.                }
  29.                context.Response.ContentType = "text/xml";
  30.                context.Response.Write((res.length == 0 ? "<results>FAILED</results>" : res))
  31.         }
  32.     }
  33. }
  34.        
  35. $return = '<results>FAILED</results>';
  36. if ( 0 == $_FILES['file']['error'] && 'image/jpeg' == $_FILES['file']['type'] = )
  37. {
  38.    $temp_file = $_FILES['file']['tmp_name'];
  39.    $destination_file = 'uplaod_dir/' . rand(1, 10000) . '.jpg';// you can change file as you want
  40.    if ( move_uploaded_file($temp_file, $destination_file) )
  41.    {
  42.        $return = '<results>SUCCESS</results>';    
  43.    }
  44. }
  45. header ("Content-Type:text/xml");  
  46. print $return;
  47. exit;