Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
How to Upload a File in PHP With Example
Sep 10, 2018 @ 15:42:38

The TutsPlus.com site has a new tutorial posted with an introductory level tutorial showing how to upload files with PHP and some example code to illustrate the process.

In this article, I’ll explain the basics of file upload in PHP. Firstly, we’ll go through the PHP configuration options that need to be in place for successful file uploads. Following that, we’ll develop a real-world example of how to upload a file.

The starts with the settings you'll need to update in your php.ini file for the temporary storage directory, the max file size, maximum post size and several others. They explain what each of the settings is for an suggest values you can use for most upload situations. They then move on to the code, showing the HTML to create the upload form and the PHP to handle the form submission. They also add in some filename sanitization and file extension restrictions.

tagged: upload file tutorial introduction

Link: https://code.tutsplus.com/tutorials/how-to-upload-a-file-in-php-with-example--cms-31763

Laravel News:
Uploading Avatar Images with Spatie’s Media Library
Mar 26, 2018 @ 15:48:05

On the Laravel News site, there's a new tutorial posted showing how you can use the Spatie Media Library package to help with the file uploads in your Laravel-based application to upload avatars for your users.

By default, the Laravel registration form contains only the name, email, and password, but often it’s useful to allow the user to upload a photo or an avatar. In this tutorial we will show you an easy way to add it, using [Spatie’s Media Library](https://github.com/spatie/laravel-medialibrary) package.

The remainder of the tutorial then breaks the implementation down into three steps:

  • Change the User Registration Form (to include the "avatar" field)
  • Upload and Store with the Media Library (installing the relation and changing the models)
  • Show an Avatar Thumbnail in the Top Navigation (using the package to resize the image)

Each step in the process includes the code or commands required to complete it. There are also several screenshots to help ensure you have the right information stored in your database.

tagged: tutorial upload avatar image spatie medialibrary package

Link: https://laravel-news.com/uploading-avatar-images

Michael Dyrynda:
Uploading files to Amazon S3 from the browser - Part One
Nov 06, 2017 @ 17:58:34

Michael Dyrynda has a tutorial posted to his site starting off a new series showing how to create the functionality in your application to upload files to Amazon S3 from the browser. The tutorial is designed for those that don't already have something in their framework that allows for this upload handling.

I recently took on a freelance project that involved having to upload media files. This is a trivially simple task to accomplish if you're using something like Laravel, using out-of-the-box support for S3 storage.

In this particular case, however, I was dealing with files potentially multiple gigabytes in size. Although a simpler to implement, I didn't want to have to have users of the site upload the file to my application - and thus server - before having my server re-upload the file to S3.

In his case, he needed something that would allow for the upload of very large files without having to pass it through the backend server to get there. He starts by walking you through the setup on the S3 side, creating an IAM policy for the upload and a form that points to the instance. The form includes a "key" value that contains the filename for the end result. He also shows some of the other options that can be included like the policy to use a redirect location and a signature to verify the upload. He then shows the code required to make it work, creating an upload route and a main form page that generates the signature and policy information for the form based on configuration options.

tagged: amazon s3 upload tutorial part1 series direct post

Link: https://dyrynda.com.au/blog/uploading-files-to-amazon-s3-from-the-browser-part-one

Alejandro Celaya:
Managing PUT requests with file uploads in psr-7 and middleware PHP applications
Mar 07, 2017 @ 19:17:01

Alejandro Celaya has posted a new tutorial to his site covering the handling of PUT requests in PSR-7 applications for file uploads via middleware.

It has been a long time since I first realized that handling file uploads in non-POST requests (like PUT) wasn't an easy task. One could assume the $_FILES array should be populated regardless the HTTP verb, but actually, PHP doesn't do it on its own.

After a long time wanting to find a solution to this problem, I've finally dedicated the time to get something functional, that allows file uploads to be transparently handled regardless the HTTP verb (it works the same way in POST, PUT and PATCH requests).

Since nowadays I try to work with psr-7/middleware based applications, I have created a Zend Expressive app that registers a middleware capable of parsing a multipart/form-data request body, populating the request's uploaded files array and parsed body array. This way, you can call $request->getUploadedFiles() or $request->getParsedBody() in any PUT or PATCH action, the same way you would do in a POST action.

His example application shows a simple HTML form that, when submitted, changes the HTTP request type based on a radio option selected at the bottom. He walks through the steps that the application takes to handle the upload via this middleware that makes it possible to work with the body of the PUT the same way as other requests. He goes through each part of the code that's required to make the middleware flow work and finishes up the post looking at a few other things to consider (like opting for POST over PUT for file uploads).

tagged: zendexpressive application tutorial psr7 middleware put request fileupload upload

Link: https://blog.alejandrocelaya.com/2017/03/06/managing-put-requests-with-file-uploads-in-psr-7-and-middleware-php-applications/

TutsPlus.com:
Programming With Yii2: Using Amazon S3
Dec 08, 2016 @ 17:27:16

The TutsPlus.com site has continued their series of posts in the "Programming with Yii2" series with this new tutorial covering the use of the Amazon S3 service for sorting files remotely in your application.

In today's tutorial, I'll walk you through the basics of browsing, uploading and downloading files to and from Amazon's cloud-based S3 storage service. Essentially, I've created a simple storage model and controller as examples which you can extend for your needs.

He starts with a brief introduction to the S3 service (including a video from Amazon themselves) and what kinds of things it could be used for. He helps you get started via the AWS web GUI, creating an S3 "bucket" and viewing their contents. He shows how to get the credentials you'll need to connect to the bucket and defining them in the ini configuration file. The tutorial then shows how to use this AWS extension for Yii2 to connect to and work with the S3 bucket you've created. This includes browsing the content, uploading new files and downloading current ones.

tagged: yii2 framework series amazon s3 file storage download upload tutorial

Link: https://code.tutsplus.com/tutorials/programming-with-yii2-using-amazon-s3--cms-26347

SitePoint PHP Blog:
Build Your Own Dropbox Client with the Dropbox API
Nov 04, 2016 @ 14:36:55

On the SitePoint PHP blog there's a new tutorial posted by author Wern Ancheta showing you how to make your own DropBox client with the help of a bit of PHP and the DropBox API.

There are lots of file hosting solutions out there, but few things compare to Dropbox because of its simplicity, auto-sync feature, cross-platform support and other cool features.

As a PHP developer you can even take advantage of their API in order to create apps that use its full capabilities. In this article, you’ll learn how to build one such app to perform different operations in a user’s Dropbox account. You will be using the Dropbox API version 2 in this tutorial. If you want to follow along, you can clone the project from Github.

They start off by walking you through the creation of an application on the DropBox side (required to connect to the API) and how to get its credentials (complete with screenshots). With that set up they get into the application - a simple Laravel-based setup that lets you connect to your account and get information like current file lists, user info and even upload new files. The tutorial includes all of the code for the controllers, models, views, routes, etc. you'll need to make it all work. There's even search functionality letting you look through current files/folders and locate certain items.

tagged: dropbox client api tutorial laravel application upload search list crud

Link: https://www.sitepoint.com/build-your-own-dropbox-client-with-the-dropbox-api/

TutsPlus.com:
How to Program With Yii2: Uploading Files
Jul 15, 2016 @ 17:15:45

On the TutsPlus.com site there's a new installment in their "How to Program With Yii2 Series" looking at implementing file uploads with some simple examples.

In this How to Program With Yii2 series, I'm guiding readers in use of the Yii2 Framework for PHP. In this tutorial, I'll guide you through the basics of uploading files and images in Yii2.

For these examples, we'll continue to imagine we're building a framework for posting simple status updates, e.g. our own mini-Twitter. The image above demonstrates writing a short update while uploading a picture I took of the Taj Mahal.

They start with a look at some of the file upload plugins that seemed like the best they found to use with Yii2: FileInput and the 2Amigos BlueImp File Uploader. They go with the first option for the rest of the tutorial, showing you how to get it installed (via Composer), updating your current database tables and changing the model to reflect these updates. Next they help you create the view with the image upload form and one to display the image result once the upload is successful (including the controller code needed).

tagged: yii2 framework series tutorial upload files plugin

Link: http://code.tutsplus.com/tutorials/how-to-program-with-yii2-uploading-files--cms-23511

Chris White:
Avoiding the burden of file uploads
Jun 14, 2016 @ 14:18:59

Chris White has a post to his site sharing a method he's come up with to avoid the burden of file uploads in your PHP application with the help of the offerings of Amazon S3 and some creative coding.

Handling file uploads sucks. Code-wise it's a fairly simple task, the files get sent along with a POST request and are available server-side in the $_FILES super global. Your framework of choice may even have a convenient way of dealing with these files, probably based on Symfony's UploadedFile class. Unfortunately it's not that simple.

[...] For most situations using S3 is a no brainer, but the majority of developers transfer their user's uploads to S3 after they have received them on the server side. This doesn't have to be the case, your user's web browser can send the file directly to an S3 bucket. You don't even have to open the bucket up to the public. Signed upload URLs with an expiry will allow temporary access to upload a single object.

He points out two advantages of this method: that you don't have to handle the upload part of file uploads and that it gives the user more control. He shares a video of the end result (a simple file upload frontend) and the code that you'll need to use the AWS PHP SDK to make it all work together. There's some configuration changes that'll need to be made on the S3 bucket side (like for CORS) but the code itself to make the connection is relatively simple. He does a great job of explaining every step of the way and includes the Javascript needed for the frontend as well.

tagged: file upload amazon s3 aws tutorial frontend

Link: https://cwhite.me/avoiding-the-burden-of-file-uploads/

Rob Allen:
PSR-7 file uploads in Slim 3
Feb 05, 2016 @ 17:08:23

In a post to his site Rob Allen explains how to handle file uploads in a PSR-7 structure, specifically illustrating with an example using the Slim (v3) framework.

Handling file uploads in Slim 3 is reasonably easy as it uses the PSR-7 Request object, so let's take a look.

He shows how to create a simple index route in a Slim application and render a view containing just a simple form with an upload field and submit button. When the form submits, he uses the getUploadedFiles method on the Slim Request object to get the file information for the upload. He also shows how to check for errors on the upload using the file data as an object and calling the getError method.

tagged: slim3 file upload tutorial handling error psr7 request

Link: https://akrabat.com/psr-7-file-uploads-in-slim-3/

SitePoint PHP Blog:
Liking, Watchlisting and Uploading through Vimeo’s API
Nov 26, 2015 @ 16:26:40

The SitePoint PHP blog continues their series looking at using the Vimeo API from PHP with the second part of their series, enhancing the previous functionality. In this new tutorial they show you how to hook in to the Vimeo API and "like" videos, add them to watchlists and even push them through as uploads.

In a previous post, we used the Vimeo API to build a rudimentary video application with Silex and Twig. We added login and user feed functionality and wrapped it all up with a video searching feature. In this one, we’ll add in liking a video, adding a video to a watchlist for later, and uploading videos via the Vimeo API.

You'll need to have the functionality from part one in place first. From there they take off running, showing you how to interact with videos to perform the "like" and "add to watchlist" actions. The interaction with the API is fired from Javascript on the page and passed through a backend script through to the API. They follow this with the handling for the uploads, using a standard file upload form for input with a few validations once submitted. The code then uses the library to pull in the contents of the file and push it through to the API.

tagged: vimeo api tutorial part2 series watchlist like upload video

Link: http://www.sitepoint.com/liking-watchlisting-and-uploading-through-vimeos-api/


Trending Topics: