Precious Takes Flight

My mother walked outside into the bright sunlight. Tears streaming down her face. Mouth turned down at the corners. Looking dazed and confused. The dust still hanging in the air from the big finale…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Simple PHP code to push files to AWS S3

So you have a web application, website or game with a PHP back-end. One of your use case is saving files to disk (images, Excel or what not). Its 2017 and you figure you should probably use a storage service instead of saving and serving files from your server.

Wait a minute, do you have to install the world to simply push a file to S3?

Here’s how I used it in my projects.

Create a php file with creds required, along with your region, and bucket name. Here’s a simple way to do that. Notice I conditionally load the constants only in prod. This allows me to fallback to local file storage instead (described in step 3) — very useful for development.

Saving to AWS is very simple. Donavan provided simple static methods to allow this. In the case AWS is not available (i.e. dev environment) I fallback to saving to a file.

There you have it. Easy peasy PHP push to S3.

Add a comment

Related posts:

What is form 941 and why it is important to the IRS?

The IRS has issued a warning stating that there are penalties for certain S-corps who do not make timely tax deposits on their federal taxes by January 31, 2022. This article will explain why it is…

Kirby Air Ride

Kirby Air Ride was the first game I fell in love with. I played the one-button racer with other kids sitting too close to tiny CRT TVs after school. There’s a cool menu screen, but of three modes I…

CNA Week 3

Hobby Lobby on Wards Road will be increasing in size by 7,000 square feet by taking over the old Kmart location next door. Mardel Christian and Education, a bookstore, will be opening next to Hobby…