This article will require some PHP programming knowledge. It is a simple form script that allows you to upload a file to a web server. It uses HTML for the front end and PHP programming language for the back end. In order to successfully accomplish this I would suggest creating a directory on the web server and let's say we will call it "upload".
Next, we need to create a simple HTML form, with a file browser button that lets you choose the file to upload to the server. Once you press submit, that file will be uploaded. Below is some sample code with explanations on each section. The first part of the script is PHP code. This code is executed once the user presses "Upload File" is pressed.
Below that where the HTML part starts is the form for the user. There is a lot of upload file script variations out on the web. I tried to break this down to its simplest form for ease. Obviously, you can change it to fit your needs...
Here are the steps to create a file upload script:
Step 1: Create a file name called uploadfile.php, open it and copy the following script into the file.
Step 2: Copy this file "uploadfile.php" to your web server using FTP. so if your website name is http://www.mywebsite.com then to run this script.
simply enter http://www.mywebsite.com/uploadfile.php
Step 3: Select a small file, preferably a picture file from your computer and press "Upload File".
The file should then upload to the same folder as this script.
Several Things to Remember:
#1: This PHP code should for the most part be self explanatory.
It checks the if block for if (trim($_POST["action"]) == "Upload File") to see if the upload file button pressed and executes the commands after that.
It simply grabs the file name that you selected from the "Browse" button and uploaded the file to the web server using that same name.
#2: Make sure the form tag has an enctype='multipart/form-data'.
This will tell the php code that there is a select file block otherwise the PHP form will not know how to grab the filename from the HTML form.
and thats about it. make sure to keep your files small because by default PHP does not allow anything over 2MB.
You can change this in the php.ini if you want to upload larger files.