Home >>Advance PHP Tutorial >PHP File Upload

PHP File Upload

PHP File Upload

Sometimes, you might want to upload your resume, Your Profile picture, any documents on the server,use File uploading concept in PHP.

With PHP File uploading concept you can easily upload your file your profile picture and your important document on the server.

PHP File uploading Form HTML script. Define form method "post" and enctype="multipart/form-data" both property must be defined for uploading a file.





	<form action="upload.php" enctype="multipart/form-data" method="post">

	  Your File Name <input type="file" name="file"/><br/>

	  <input type="submit" value="Upload" name="upload"/>




Output Your File Name

The enctype attribute of the <form> tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data, like the contents of a file, to be uploaded.

The type="file" attribute of the <input> tag specifies that the input should be processed as a file.

For example, when viewed in a browser, there will be a browse-button next to the input field.



	if ($_POST['upload'] )


      "upload/" . $_FILES["file"]["name"]);  

       echo "Upload: " . $_FILES["file"]["name"] . "<br>";

       echo "Type: " . $_FILES["file"]["type"] . "<br>";

       echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";

       echo "Stored in: " . $_FILES["file"]["tmp_name"];


Output Upload: filename Type: extension Size: size of the file in bytes Stored in: temporary file location

Note : first create a folder named upload By using the global PHP $_FILES array you can upload files from a client computer to the remote server.

The first index is the form's inputted name and the second index may be either "name", "type", "size", "tmp_name" of the file such as => $_FILES["file"]["name"] : The name of the uploaded file => $_FILES["file"]["type"] : The type of the uploaded file => $_FILES["file"]["size"] : The size in kilobytes of the uploaded file => $_FILES["file"]["tmp_name"] : The temporary name of the file