---
title: "Uploading File into Server using PHP"  
description: "In this article I will show you, how to upload file into server in PHP. Let’s have an example, how to upload file into server using PHP.  Creating Fil"  
author: "Anonymous User"  
published: 2011-09-26  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/744/uploading-file-into-server-using-php  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# Uploading File into Server using PHP

In this [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370) I will show you, how to [upload](https://www.mindstick.com/forum/12860/how-to-upload-file-asynchronously-using-generic-handler) file into [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) in PHP. Let’s have an example, how to upload file into server using PHP.\

##### Creating File Uploading Form:

Here I am [giving](https://yourviews.mindstick.com/view/81621/natural-disasters-in-2020-giving-us-alarm-warning) an example to file uploading [form](https://yourviews.mindstick.com/view/87344/explained-the-benefits-of-short-form-videos).

```
<!DOCTYPE html><html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">         <title></title>     </head>     <body>         <form id ="frmBody"method="post" action="FileUpload.php" enctype="multipart/form-data">                 <table>                     <tr>                         <td>Select File :</td>                         <td> <input type="file" name ="file" id ="file" width="300px"></input> </td>                     </tr>                     <tr>                         <td> </td>                         <td><input type ="submit" name ="btnsubmit" value =" Upload"></input> </td>                     </tr>                 </table>             </form>     </body></html>
```

##### Form Design:

![Uploading File into Server using PHP](https://www.mindstick.com/mindstickarticle/1d7005fe-de8f-4088-9b30-0b5464ff36b1/images/3eb68863-5caa-4478-be27-2c4d7d95bfeb.png)

Here you can browse file (i.e. select file for uploading into server) by clicking on ‘Browse button. After selecting file, click on ‘Upload’ button for uploading file into server.

When you click on ‘Upload’ button then ‘FileUpload.php’ php script is called.

```
<?php       // Check error duringfile uploading         if($_FILES["file"]["error"] > 0)        {            // display error message            echo "<b>Error</b>".$_FILES["file"]["erro"]."</br>";        }        else        {            // display uploding file information               echo "<b>File Upload:</b> " . $_FILES["file"]["name"] . "<br/>";              echo "<b>File Type: </b>" . $_FILES["file"]["type"] . "<br/>";              echo "<b>File Size: </b>" . ($_FILES["file"]["size"] / 2048) . " Kb<br/>";              echo "<b>Stored in Place:  </b>" . $_FILES["file"]["tmp_name"];        }?>
```

##### Output:

![Uploading File into Server using PHP](https://www.mindstick.com/mindstickarticle/1d7005fe-de8f-4088-9b30-0b5464ff36b1/images/c7b6b7fb-927b-44b9-9300-0a93e5dfdeea.png)

When you [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social) on Browse [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) then [dialog box](https://www.mindstick.com/blog/157/dialog-box-in-dot-net) will be open where you can [select](https://www.mindstick.com/forum/34066/use-select-operator-in-linq) a file to upload on server.

![Uploading File into Server using PHP](https://www.mindstick.com/mindstickarticle/1d7005fe-de8f-4088-9b30-0b5464ff36b1/images/a357eeea-d226-40c8-944e-52b78428ab8d.png)

Now click on ‘Upload’ button, we will get following output.

![Uploading File into Server using PHP](https://www.mindstick.com/mindstickarticle/1d7005fe-de8f-4088-9b30-0b5464ff36b1/images/1dca65e4-4da8-4549-bdac-6039c835a491.png)

Example:

##### Uploading file into server with some restriction

```
<?php       //  check uploadingfile restriction     $ext = substr($_FILES["file"]["name"], strrpos($_FILES["file"]["name"], '.') + 1);      if(($_FILES["file"]["type"] == "image/jpeg") || ($ext == txt))      {       // Check error during file uploading         if($_FILES["file"]["error"] > 0)        {            // display error message            echo "<b>Error</b>".$_FILES["file"]["erro"]."</br>";         }        else        {            // display uploding file information               echo "<b>File Upload:</b> " . $_FILES["file"]["name"] . "<br/>";              echo "<b>File Type: </b>" . $_FILES["file"]["type"] . "<br/>";              echo "<b>File Size: </b>" . ($_FILES["file"]["size"] / 2048) . " Kb<br/>";              echo "<b>Stored in Place:  </b>" . $_FILES["file"]["tmp_name"];                        if (file_exists("Upload/".$_FILES["file"]["name"]))              {                  echo $_FILES["file"]["name"] ."already exist";              }              else              {                  // Save file within UploadFiles directory                  move_uploaded_file($_FILES["file"]["name"], "UploadFiles/".$_FILES["file"]["name"]).'</br>';                  echo "Stored in:"."Upload/".$_FILES["file"]["name"];              }        }      }      else       {          echo 'Invalid file format';        }?>
```

##### Output:

![Uploading File into Server using PHP](https://www.mindstick.com/mindstickarticle/1d7005fe-de8f-4088-9b30-0b5464ff36b1/images/23349e11-e3fc-4051-b29b-7ee6760b718c.png)

\

---

Original Source: https://www.mindstick.com/articles/744/uploading-file-into-server-using-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
