How to upload File On Server in Php

Example 1:
<html>

<form method="post" enctype="multipart/form-data">

<input type="file" name="file1"><br>

<input type="submit" name="btnupload" value="Upload">


</form>

</html>

<?php if(isset($_REQUEST['btnupload']))
{

if($_FILES['file1']['type']=="image/gif" or $_FILES['file1']['type']=="image/jpeg")

{ move_uploaded_file($_FILES['file1']['tmp_name'],$_FILES['file1']['name']); echo $_FILES['file1']['tmp_name']."<br>"; //display temporary directory
echo $_FILES['file1']['name']."<br>"; //name of the uploaded file.

echo $_FILES['file1']['type']."<br>"; //display  MIME type of the uploaded file.

echo ($_FILES['file1']['size']/1024)."KB<br>";// size in bytes of the uploaded

} Else
echo "You can upload image files only ...";
}
?>
The following HTM code below creates an uploader form. This form is having method attribute set to post and enctype attribute is set to multipart/form-data

Form Attributes:
   ENCTYPE=”nultipart/form-data:- necessary for the form element of the type file to function properly.
   ACTION=fileupload.php:- the name of the PHP page that holds the code that actually uploads the file to the web server

How to upload File On Server in Php How to upload File On Server in Php Reviewed by Unknown on 21:09:00 Rating: 5

No comments:

Powered by Blogger.