2

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.

3
  • what language and database? you may want to try google again because a simple "html image upload" search returns tens of thousands of results. Commented Mar 13, 2012 at 21:30
  • 1
    Using what server side technology? PHP? A Microsoft flavour? Perl? Ruby? Something else? Commented Mar 13, 2012 at 21:31
  • Sorry, I have seen the upload code. I am after the feature to have the images that have been uploaded to be viewed in a gallery on my site. Commented Mar 14, 2012 at 0:44

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

2

In order to get a list of files in a directory (assumes the file path is known ahead of time) you can do something like this:

$filePath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'uploads'; $files = scandir($filePath); 

If you wanted to filter this down to look for image files you could use something like this:

$filePath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'uploads'; $files = scandir($filePath); $imageFiles = array_values(preg_grep('/^.*?\.((gif)|(png)|(jpe?g))$/', $files)); 

And for a good guide on uploading the files you can check out http://www.exchangecore.com/blog/how-upload-files-html-php/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.