From the course: PHP Techniques: Working with Files and Directories

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Moving uploaded files

Moving uploaded files - PHP Tutorial

From the course: PHP Techniques: Working with Files and Directories

Start my 1-month free trial

Moving uploaded files

- We know how to use PHP to upload a file to a temporary location. Now, let's learn how to store it somewhere permanent. To do that, we will use a PHP function called move_uploaded_file. It takes two arguments: the path to the temporary file and the path to its destination. It's called move_uploaded_file because it doesn't move just any file. It also verifies that the file is a valid upload file which was recently uploaded via a post request. This is a good security measure that restricts the action to uploaded files only. Note that this will overwrite any file that's already at that destination. So you may want to pair it with the check for file exists if you want to prevent overriding. I'm going to start by creating a new directory for our completed downloads. So I'll come over here, make a new folder, which I'll call uploads, and I will put that into my PHP sandbox. And then I'm going to click on it and check…

Contents