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 - PHP Tutorial
From the course: PHP Techniques: Working with Files and Directories
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
-
-
-
-
-
(Locked)
Configuring PHP for file uploads1m 52s
-
(Locked)
Sending files as form data3m 51s
-
(Locked)
Inspecting uploaded files4m 54s
-
(Locked)
Moving uploaded files5m 7s
-
Handling upload errors4m 2s
-
(Locked)
Setting file permissions6m 7s
-
(Locked)
Securing file uploads2m 15s
-
(Locked)
Challenge: Profile photo3m 48s
-
(Locked)
Solution: Profile photos4m 3s
-
(Locked)
-