0

I am looking for a code(php or javascript) that can enable me to upload files to my site eg images and when i vist my site at that particular posted page i should see the image not a link but the thumb nail like what happens with gmail or face book. when I upload a file(text) i should see a link that can allow me either to view the file or download the file.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by leest35
0
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {


    if (file_exists("images/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
        $image= time()."-". $_FILES["file"]["name"];
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/". $image);

      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>
<html>
<body>
<form action = "imgupload.php" enctype="multipart/form-data" method = "post">
<label> Your Image:</label>
<input type = "file" name = "file" /><br /><br />

<input type = "submit" name = "submit" value = "submit" /><br /><br />
</form>

Edited by Dani: Formatting fixed

0

There are hundreds of tutorials on the net on how to do this, perosnally i would rather use a tutorial than ask for the code, when you work through the tutorial you will know how and why it works, this helps you to modify it and to further develop it and solve any issues that may arise. Even though Daniel was nice enough to post some code for you, i would still recommend you find some tutorials and use those to develop exactly what you want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.