Table of Contents
Preface
PHP version restrictions
Upgrade WAMP 2.5-3.1
Install the storage emulator
Three ways to terminate the process
Address
Home Backend Development PHP Tutorial PHP upload files using Azure Storage Blob

PHP upload files using Azure Storage Blob

Jul 05, 2018 pm 02:04 PM
php use

This article mainly introduces PHP's use of Azure Storage Blob to upload files. It has certain reference value. Now I share it with you. Friends in need can refer to it.

Preface

Distribution When it comes to a project, a small website that requires content management, the front-end page display and special effects are completed by front-end colleagues. I am responsible for building the content management backend and providing data interfaces. This project requires the management side to be able to upload videos, but the server bandwidth provided by Party A is very small, and there are other projects running in parallel on the same server.
In order to prevent the subsequent impact of sudden upgrades, the team leader suggested that I learn to use Azure Storage Blob and be ready for upgrades at any time.

PHP version restrictions

I found the official sdk in Github.

Minimum Requirements

PHP 5.6 or above

Since the locally configured PHP environment is 5.5.12, and the sdk requires The minimum PHP version is 5.6, composer blocked the update
So use composer update --ignore-platform-reqs to bypass the requirement monitoring and force the upgrade.
However, if const is set to an array in the classBlobResources.php, an error will be reported in 5.5

Fatal error: Arrays are not allowed in class constants in E:\webroot\tp5cms\vendor\microsoft\azure-storage-blob\src\Blob\Internal\BlobResources.php on line 103
Copy after login

There is no choice but to upgrade PHP.

Upgrade WAMP 2.5-3.1

For development needs, we decided to upgrade wampserver to the latest version.
There is a trick to upgrading wamp: you cannot directly overwrite the installation. You must first remove the old version and then install the new version.
Read the upgrade tips carefully.
To summarize, what needs to be done is probably the following two things:

  • Remove the service

    Start WampServer
    [Important] Log in to MySQL backup All database data
    wampmanager -> Stop all Services
    wampmanager -> MySQL -> Service -> Remove service Remove MySQL service
    wampmanager -> Apache -> Service -> Remove service Remove the Apache service
    stop wampmanager
    Right-click wampmanager -> Exit

  • Rename the folder

    Rename wamp Name it another name for backup

Install the storage emulator

Since there is no azure account for testing in the company, fortunately azure has one for testing and development Storage emulator. Windows systems can be downloaded and installed directly, and Linux systems can use the open source storage emulator Azurite.

  1. Download the simulator, here is the download link.

  2. After the installation is complete, run StartStorageEmulator.cmd and find that you need to install SQL Server Express Local DB. There is a download link here. Select Express Edition, then select LocalDB to download and install.

  3. Run cmd again and found the error

C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>AzureStorageEmulato
r.exe start
Windows Azure Storage Emulator 5.3.0.0 command line tool
 
未经处理的异常: System.TimeoutException: Unable to open wait handle.
在 Microsoft.WindowsAzure.Storage.Emulator.Controller.EmulatorProcessControll
er.InternalWaitForStorageEmulator(Int32 timeoutInMilliseconds)
在 Microsoft.WindowsAzure.Storage.Emulator.Controller.EmulatorProcessControll
er.EnsureRunning(Int32 timeoutInMilliseconds)
在 Microsoft.WindowsAzure.Storage.Emulator.Commands.StartCommand.RunCommand()
 
在 Microsoft.WindowsAzure.Storage.Emulator.Program.Main(String[] args)
Copy after login

After querying, I found that this was because a process occupied port 10000.

#运行:>C:\Users\Walter>netstat -p tcp -ano | findstr :10000> TCP 127.0.0.1:10000 0.0.0.0:0 LISTENING 2664
 #根据PID 2664查询对应的进程>C:\Users\Walter>tasklist | findstr "2664">YunDetectService.exe 2664 Console 1 9,944 K
 
#只是一个不重要的进程,去掉后继续开发>C:\Users\Walter>taskkill /pid 2664 /f>成功: 已终止 PID 为 2664 的进程。
 
#以下是模拟器成功运行的范例>C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>AzureStorageEmulator.exe start
Windows Azure Storage Emulator 5.3.0.0 command line tool
The storage emulator was successfully started. 
>C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator>AzureStorageEmulator.exe status
Windows Azure Storage Emulator 5.3.0.0 command line tool
IsRunning: True
BlobEndpoint: http://127.0.0.1:10000/QueueEndpoint: http://127.0.0.1:10001/TableEndpoint: http://127.0.0.1:10002/
Copy after login

Start development

You can try adding container, blob and deletion functions through official examples.
After successfully uploading the blob, the resources in the storage simulator cannot be addressed.
eg. The account name used is devstoreaccount1, the created container name is mycontainerudfpbk, and the blob name is 5ac1a5c82021d.png.
According to the rules in the document, the resource address should be
http://127.0.0.1:10000/devstoreaccount1/mycontainerudfpbk/5ac1a5c82021d.png
but the returned data has always been

<Error>
  <Code>ResourceNotFound</Code>
  <Message>    The specified resource does not exist. RequestId:9d2d1b08-12b1-4feb-8636-4325eb71b838 Time:2018-04-08T09:14:14.3007800Z
  </Message>
</Error>
Copy after login

After reading related articles, I found that when creating a container, if the access permissions (container-level access policies) are not set, external access is prohibited by default.

ACL (PublicAccessType) permissions are divided into three levels: CONTAINER_AND_BLOBS, BLOBS_ONLY, NONE, the default is NONE.
If the resource needs to be accessible externally, set it to BLOBS_ONLY.
Attach your own encapsulated azure auxiliary class

I also encountered a small problem. When setting permissions, ACLBase reported an error
Static function MicrosoftAzure\Storage\Common\ Internal\ACLBase::createAccessPolicy() should not be abstract
After querying, it was found that abstract and static are not allowed to be used in methods at the same time after PHP5.2.

#只要将ACLBase中的abstract protected static function createAccessPolicy();abstract protected static function validateResourceType($resourceType);#改为protected static function createAccessPolicy(){}protected static function validateResourceType($resourceType){}#即可
Copy after login

Summary

Three ways to terminate the process

  1. Use pid to end the process
    taskkill / pid PID /f

  2. Use pid to end the process
    ntsd -c q -p PID

  3. Use Process name End process
    ntsd -c q -pn NAME.exe

Address

  1. Officially provided sdk Address

  2. Self-use auxiliary class address

Note: Please clarify the role of this process before forcing the end

The above is the purpose of this article All content, I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Introduction to PHP background image upload works

Introduction to using ajax to transfer values ​​between js and php

The above is the detailed content of PHP upload files using Azure Storage Blob. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log Analysis PHP Logging: Best Practices for PHP Log Analysis Mar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

HTTP Method Verification in Laravel HTTP Method Verification in Laravel Mar 05, 2025 pm 04:14 PM

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

Discover File Downloads in Laravel with Storage::download Discover File Downloads in Laravel with Storage::download Mar 06, 2025 am 02:22 AM

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

See all articles