Creating a directory for uploads

When PHP sees that a file is being uploaded, it will save that file to a temporary location. Once we have validated the other form fields, we should move that file to a publicly accessible directory. We want to show this image on our website, so it should be somewhere within the document root of the server, that is, in public/. It would be smart to make a distinction between the static resources of the website itself (elephpant.jpg, bootstrap.min.css, etc.) and dynamic resources that are uploaded by users. So let’s create a dedicated directory for uploaded files in public/. Let’s call this directory uploads.

Get hands-on with 1200+ tech skills courses.