# File Uploader script for Your website



## carsey (Aug 19, 2006)

Hi people :wave:

This PHP script is aimed to make your website have a great feature of a uploader so people can easily upload files/images to your hosting servers without and hassle.

First of all, we need to have a look at the code.


```
<?php
/*************************************************
 * Created By Hosting-Town.com
 * Open to use for anyone
 * CopyRight must remain in place
 * Hosting-town.com
 ****************************************************/

//Upload Locacation E.G. ./uploads/
$uploadLocation = "./";


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Uploader!</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
   <style type="text/css">
<!--
.style1 {
	font-size: 10px;
	font-weight: bold;
}
-->
   </style>
</head>
<body>
    <div id="main">
      <div id="caption">UPLOAD FILE</div>
      <div id="icon"> </div>
      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data">
        File to upload:<center>
        <table>
          <tr><td><input name="upfile" type="file" size="36"></td></tr>
          <tr><td align="center"><p><br/>
            <input class="text" type="submit" name="submitBtn" value="Upload">
          </p>
              <p align="right" class="style1"><a href="http://hosting-town.com">Made By Hosting-Town.com - James Addison </a></p></td>
          </tr>
        </table></center>  
      </form>
<?php    
    if (isset($_POST['submitBtn'])){

?>
      <div id="caption">RESULT</div>
      <div id="icon2"> </div>
      <div id="result">
        <table width="100%">
<?php

$target_path = $_SERVER['DOCUMENT_ROOT'] . '[B]/mp3s/[/B]' . basename( $_FILES['upfile']['name']);
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
    echo "The file".  basename( $_FILES['upfile']['name']).
    "has been sucessfully uploaded.";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>
        </table>
     </div>
<?php            
    }
?>
    <div>
	
	Please note: You are solely responsible for any content that you may choose to upload to this site.  The site owner/administrator will not accept ANY responsibility regarding illegal content that you upload.  Should you not agree to these terms, please leave this page now.
</body>
```
This is the code that will allow people to upload to your site.

*Please note that there is currently no file restrictions on this script so anyone visiting your site will be able to upload any type of file of any size*

Now, open the above in your favourite text editor, such as notepad and change the area in *bold* in the code to the location as to where you want the files to be uploaded to. For example: If you want all uploads go to a folder called */uploads* you would make the code look like:


```
$target_path = $_SERVER['DOCUMENT_ROOT'] . '[B]/uploads/[/B]' . basename( $_FILES['upfile']['name']);
```
Now, after you have made the above changes, save the files as *uploads.php* and upload it to the area of your site. Also, upload the folder *styles* to the same directory as *upload.php*

Also, remember to make sure that your *uploads* folder has full write permissions (CHMOD 777).

Now, you will be able to test the script by going to the URL where you uploaded the PHP file.

If successful, the script will tell you its successful by showing: *The file (your filename) has been successfully uploaded.*


This script can be used openly by anyone as long as the full copyright markings stay in place. Please bear in mind, this script was written in our own time for free for you.


----------



## carsey (Aug 19, 2006)

STAFF... This is a incomplete version of this article/script. New version is to include a easy setup configuration.

*PLEASE LEAVE THIS ONE IN THE MODERATED QUEUE*


----------

