SIGN UP MEMBER LOGIN:    
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 !!

Login to add your contents and source code to this article
share this article :
post comment
 

u r absolutely right friend but the link provided in the article is used in my local machine so if u want to run the code you need to have XAMPP server and follow the step i provided in the article. or for more help do follow the given steps -- Step 1 : open XAMPP , start the service like Apache and MySQL Step 2 : open the browser Step 3 : start typing in the address bar http://localhost/yourfolder/filename with extension, here Ur folder means means C:\xampp\htdocs\yourfolder\ -- file saved in this location. try it . it may help you !!!!!!!!!!

Posted by Mike Steward Dec 13, 2011

wanted to know more but the output url you provided ( http://localhost/yourfoldername/fileupload.html ) is not working. plz correct this..

Posted by Manoj Singh Panwar Dec 13, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor