title: Use form post (php) to upload a file to Azure storage, and return the link
body: <p>I have read a number of solutions here and elsewhere that show how a upload a file to an Azure Blob storage. I have the php code working below when the file is hard coded (followed the MS tutorial), but not if I try to post the file to the PHP (get error: not a valid path). I want a user to be able to browse to a file in the form and submit (then return the url so that I can use it for other actions). I read on SO that javascript shows a fake path for security, and I assume that is my issue. How, then, do I get the proper path to the PHP file if I cannot post it. I have tried a default post and an ajax attempt. Is there a solution?</p>
  
  <p>My PHP (works when the file is hard coded):</p>
  
  <pre><code> require_once 'WindowsAzure\WindowsAzure.php';
   use WindowsAzure\Common\ServicesBuilder;
   use WindowsAzure\Common\ServiceException;
  
   $connectionString = "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey";
   // Create blob REST proxy.
   $blobRestProxy = ServicesBuilder::getInstance()-&gt;createBlobService($connectionString);
  
   //$content = fopen("c:\myfile.txt", "r"); //this works when hard coded like this
   //$blob_name = "myblob.txt";
   //get posts
   //$fpath = $_POST["resFile"];//tried this too - no go
    $fpath = $_FILES["resFile"];
    $fname = "hello.txt";
  
    $content = fopen($fpath, "r"); //I know this isn't right, but trying
    $blob_name = $fname;
  
   try {
       //Upload blob
       $blobRestProxy-&gt;createBlockBlob("saskcontainer", $blob_name, $content);
   }
   catch(ServiceException $e){
  // Handle exception based on error codes and messages.
  // Error codes and messages are here: 
  // http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
  $code = $e-&gt;getCode();
  $error_message = $e-&gt;getMessage();
  echo $code.": ".$error_message."&lt;br /&gt;";
   }
   //and I need to return the url here on success
  </code></pre>
  
  <p>here is the HTML and JS:</p>
  
  <pre><code> &lt;form action="test.php" method="post" enctype="multipart/form-data"&gt;
   &lt;div data-role='page' id="resFileCont" &gt;
  
      &lt;input type="file" name="resFile" id="resFile" value="" /&gt;
      &lt;!--&lt;input type="text" name="name" /&gt;--&gt;
      &lt;input type="submit" value="Submit" data-inline="true"/&gt;
  &lt;/div&gt;&lt;/form&gt;
  &lt;div id="res"&gt;&lt;/div&gt;
  &lt;script&gt;
      $(document).ready(function () {
          $("form").on('submit', (function (e) {
              e.preventDefault();
  
              $.ajax({
                  url: "test.php", // Url to which the request is send
                  type: "POST",             // Type of request to be send, called as method
                  data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                  contentType: false,       // The content type used when sending data to the server.
                  cache: false,             // To unable request pages to be cached
                  processData: false,        // To send DOMDocument or non processed data file it is set to false
                  success: function (data)   // A function to be called if request succeeds
                  {
                      alert(data)
                      $("#res").html(data)
                  }
              });
          }));
      });
  &lt;/script&gt;
  </code></pre>