The Azure Storage PHP client libraries will be retired on 17 March 2024. I was able to find a sample of how to do this programmatically for Azure Files. Please check and let me know if this works for you.
// Create a SharedAccessSignatureHelper
global $connectionString;
$settings = StorageServiceSettings::createFromConnectionString($connectionString);
$accountName = $settings->getName();
$accountKey = $settings->getKey();
$helper = new FileSharedAccessSignatureHelper(
$accountName,
$accountKey
);
// Generate a file readonly SAS token
// Refer to following link for full candidate values to construct a service level SAS
// https://docs.microsoft.com/en-us/rest/api/storageservices/constructing-a-service-sas
$sas = $helper->generateFileServiceSharedAccessSignatureToken(
Resources::RESOURCE_TYPE_FILE,
"$shareName/$fileName",
'r', // Read
'2030-01-01T08:30:00Z' // A valid ISO 8601 format expiry time
);
$connectionStringWithSAS = Resources::FILE_ENDPOINT_NAME .
'='.
'https://' .
$accountName .
'.' .
Resources::FILE_BASE_DNS_NAME .
';' .
Resources::SAS_TOKEN_NAME .
'=' .
$sas;
$fileClientWithSAS = FileRestProxy::createFileService(
$connectionStringWithSAS
);
// Get a downloadable file URL
$fileUrlWithSAS = sprintf(
'%s%s?%s',
(string)$fileClientWithSAS->getPsrPrimaryUri(),
"$shareName/$fileName",
$sas
);
Hope this helps! Let me know if you have any questions.
If you still have questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.
If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community.
Thank you for helping to improve Microsoft Q&A!