All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

PHP File Uploading

You can use PHP to upload files to server with the help of HTML Form

Example of File Upload

<!--This is file.html file-->

<!DOCTYPE html>

<form action = "upload.php" method = "post" 
enctype = "multipart/form-data">
    <input type="file" name="Uploadfile" id="file">
    <input type="submit" value="Upload Image" name="submit">



/*This is getfile.php file*/

echo $_FILES['Uploadfile']['name'];
echo $_FILES['Uploadfile']['type'];
echo $_FILES['Uploadfile']['size'];


Code Explanation

  • $_FILES is used to get the files and its content.

  • $_FILES['file']['tmp_name']- the uploaded file in the temporary directory on the web server.

  • $_FILES['file']['name'] - the actual name of the uploaded file.

  • $_FILES['file']['size'] - the size in bytes of the uploaded file.

  • $_FILES['file']['type'] - the MIME type of the uploaded file.

  • $_FILES['file']['error'] - the error code associated with this file upload.

❮ PrevNext ❯