Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML code to upload images

Tags:

html

Can someone please provide me with some links (or source code) for me to research about how to upload images to a website (by the community) and for these images to be viewed online by the community.

I have searched via google, but have had no luck.

Thank you.

EDIT

Sorry, I have actually seen many examples to upload files. I am wanting (if possible) to be able to upload images, and then have them arranged in some kind of gallery so that the community can see/view them.

I am after a range of different technologies that are available on the WWW if possible.

like image 531
Garry Avatar asked Feb 19 '26 22:02

Garry


2 Answers

Copy the below codes and save it as upload.php or anything.php (note it should be saved as php extension and should be run on apache server or any server supporting php).

<?php
if(isset($_REQUEST['submit']))
{
  $filename=  $_FILES["imgfile"]["name"];
  if ((($_FILES["imgfile"]["type"] == "image/gif")|| ($_FILES["imgfile"]["type"] == "image/jpeg") || ($_FILES["imgfile"]["type"] == "image/png")  || ($_FILES["imgfile"]["type"] == "image/pjpeg")) && ($_FILES["imgfile"]["size"] < 200000))
  {
    if(file_exists($_FILES["imgfile"]["name"]))
    {
      echo "File name exists.";
    }
    else
    {
      move_uploaded_file($_FILES["imgfile"]["tmp_name"],"uploads/$filename");
      echo "Upload Successful . <a href='uploads/$filename'>Click here</a> to view the uploaded image";
    }
  }
  else
  {
    echo "invalid file.";
  }
}
else
{
?>
<form method="post" enctype="multipart/form-data">
File name:<input type="file" name="imgfile"><br>
<input type="submit" name="submit" value="upload">
</form>
<?php
}
?> 

And you should create two folders("uploads" and "tmp") in the parent directory (Where the script executes).

Now your upload script is ready. It's simply an upload script with which you can upload one image at a time.

like image 66
Venkat Selvan Avatar answered Feb 22 '26 15:02

Venkat Selvan


Here's a good, basic start using PHP: http://www.w3schools.com/php/php_file_upload.asp

like image 23
Brian Avatar answered Feb 22 '26 14:02

Brian