Forgot Password / Register
Site Statistics
Total Members: 510
Total Tutorials: 242
Newsest User: Hp
Todays Unique Hits: 121
0 Users 2 Guests Online

Basic File Upload System

Allow users to upload files to your website

The HTML Element of our file uploader

1
2
3
4
5
6
7
8
9
<html>
<body><form action="doupload.php" method="post"
enctype="multipart/form-data">
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" /> 
 
<input type="submit" name="submit" value="Submit" />
</form></body>
</html>


The PHP Element of our file uploader (doupload.php)

doupload.php Copy to clipboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 30000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "";
    echo "Type: " . $_FILES["file"]["type"] . "";
    echo "Size (Kb): " . ($_FILES["file"]["size"] / 1024) . " ";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "";    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Saved to: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>


Enjoy :)
Dava
Author:
Views:
1557
Rating:
Posted on Sunday 27th July 2008 at 05:01 PM
ilyas-shezad
ilyas-shezad
I love it! Nice good work on this one.
I've worked with other upload scripts before but i like this one its nice and simple.