Friday 14 July 2017

Download the Azure SDK for PHP and upload the video in Azure

Download the Azure SDK for PHP and upload the video in Azure

Download the Azure SDK for PHP

  1. Install Git. (If already, move to next)
  2. Create composer.json and add following contents.
    {
             "require": {
               "microsoft/azure-storage": "*"
             }
           }
  3. Download composer.phar in your project root.
  4. Execute following Command.
    php composer.phar install
  5. It will download the Library, which I have tested.



Upload the Media in Azure

  1. Include following files:
    use WindowsAzure\Common\ServicesBuilder;
    use MicrosoftAzure\Storage\Common\ServiceException;
    require_once 'azure/vendor/autoload.php';
  2. Get the Credentials
    $azureUserName='XXXXXXXXXXXX';
    $azureKey='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
    $containter='XXXXXXXXX';
    
  3. Set the Credentias
    $connectionString = "DefaultEndpointsProtocol=http;AccountName={$azureUserName};AccountKey={$azureKey}";
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
  4. Upload the File in Azure
    $blobName='textFile.txt';
    $content = fopen('../data/test6.txt', "r");
    try    {
                
                $blobRestProxy->createBlockBlob($containter, $blobName, $content);
                echo 'Uploaded successfully';
            }
            catch(ServiceException $e){
                $code = $e->getCode();
              $e->getMessage();
    
            }