ARTICLE

File uploading in PHP using XAMPP

Posted by Mike Steward Articles | PHP December 11, 2011
In this article we are going to understand how to upload a file with the help of PHP. For this purpose you must install a XAMPP server.
Reader Level:

File uploading

Hi guys, in this article we are going to understand how to upload a file with the help of PHP. For this purpose you must install a XAMPP server.

Uploading a file from the form is really a good concept to have with your web application.

Let us see how we can create a form for loading up a file, so firstly we require a design part using HTML The following is the script :

HTML script

<html>
<
body bgcolor="pink">
<center>
<
h3> FILE UPLOADING </h3>
<
hr>
<
form action="fileupload.php" method="post" enctype="multipart/form-data">
<
label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</
center>
</
body>
</html>

Save it as fileupload.html !

Result of above scripting

The above given code displays a web page having a browse input box and  asubmit button in it, here is what your web page looks like :

z1.gif

PHP scripting for file uploading

<html>
<
head><title>File uploaded</title></head>
<
body bgcolor="cyan" color="yellow">
<center>
<
h3>File uploaded !! <h3>
<
hr>
<?php
if ($_FILES["file"]["error"] > 0)
  {
 
echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
 
{
 
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"];
  }
?>
</center>
</
body>
</html>

Saved it by fileupload.php !

Output of the above scripting

To  run the code Open XAMPP server start the services like Apache and MySQL .Open the browser type: http://localhost/yourfoldername/fileupload.html


z1.gif

Click on the Browse button you will have file upload window:

z4.gif

Select the file to upload then click open you will have a url of that file at your browse input box as given below :

z2.gif

After clicking on the submit button the final result will display :

z5.gif

Conclusion : This is the information of your uploaded file. Thanks !!

COMMENT USING

Trending up