To upload a file using PHP, you need to create an HTML form that includes a file input field, and then handle the file upload in the PHP script that receives the form submission.
Here's an example HTML form:
152 chars5 lines
The enctype="multipart/form-data"
attribute is necessary to allow file uploads.
And here's an example PHP script that handles the file upload:
main.php732 chars26 lines
This script first checks for any errors during the file upload, then checks the file type to make sure it's an image (in this example), and finally moves the uploaded file to a specified directory.
Note that you'll need to make sure the destination directory is writable by the web server process.
gistlibby LogSnag