I moved my PHP code from Redhat to Azure Web App and can't get following code work:
$foldername = "repository/" . $newdir;
mkdir($foldername);
Any ideas?
If you need to store something quickly, you might want to include the current directory to ensure the directory is created in the same location as the file it's called from. Also make sure that you set the flag to true for writing recursively.
$foldername = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'repository')
. DIRECTORY_SEPARATOR . $newdir;
if (false === mkdir($foldername, 0775, true)) {
throw new \RuntimeException('Cannot create directory ' . $foldername . '!');
}
With Microsoft Azure (or any other cloud provider) there's no single "LAMP" stack anymore. This means your web application (PHP code) runs on platform instances (Web App), your database runs on a distributed cluster (ClearDB) and your files are kept on a scalable and redundant storage (Azure Blob Storage). This follows the S.O.L.I.D. principles and allows your application to scale easily without being restricted.
The instance where you run your PHP code doesn't have that much space to store and keep files. A better way is to offload your files as quickly as possible to a shared storage platform that offers redundant backups and can scale/grow with your application requirements. This also means that with a central storage, multiple instances can now share your uploaded files in a secure way, even provide CDN for static files you use in your web application.
I've created a PoC to browse Azure Storage containers, which you can checkout yourself from https://github.com/azureblob/azureblob to see how you can use the Azure SDK for PHP to interact between your web application and the blob storage.
Feel free to reach out to me if you have more questions in setting up a blob storage for your uploaded files (or any other Azure related question).