+ Reply to Thread
Results 1 to 7 of 7

 

Thread: Recommend Me a Simple PHP Image Upload Script

  1. #1
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,008
    Thanks
    54
    Thanked 180 Times in 161 Posts


    Hi All

    Can anyone recommend me a simple PHP image upload script? It just needs to be able to upload one image to a particular folder on my server, I don't need anything particularly fancy, just looking for a best practice script.

    Thanks

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Jan 2008
    Location
    Yorkshire
    Posts
    536
    Thanks
    22
    Thanked 37 Times in 31 Posts
    something like this should work

    HTML Code:
    <form enctype="multipart/form-data" action="image-upload.php" method="POST">
    <fieldset>
    <input name="theimage" type="file" />
    <input type="submit" value="Upload" />
    </fieldset>
    </form>
    and then in image-upload.php

    PHP Code:
    $target_path "/home/ACCOUNTNAME/public_html/images/";

    $target_path $target_path basename$_FILES['theimage']['name']);

    if(
    move_uploaded_file($_FILES['theimage']['tmp_name'], $target_path)) {
    echo 
    "<p>The image ".  basename$_FILES['theimage']['name']). " has been uploaded</p>";
    } else{
    echo 
    "<p>There was an error uploading the image, please try again!</p>";


  3. The Following User Says Thank You to Andrew Starr For This Useful Post:

    accelerator (02-06-09)

  4. #3
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,008
    Thanks
    54
    Thanked 180 Times in 161 Posts
    Thanks for that.

    Rgds

  5. #4
    a4uDarian's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2008
    Posts
    199
    Thanks
    19
    Thanked 43 Times in 30 Posts
    As far as I can see there's nothing in that script to stop people uploading executable scripts - and as you're moving the file to a place that is publicly accessible I would by very careful using this without some form of extra validation in place (to check the file really is a harmless image).

    More here: make upload file (move_uploaded_file) secure for public usage - CodingForums.com

  6. #5
    Registered User

    Status
    Offline
    Join Date
    Jan 2008
    Location
    Yorkshire
    Posts
    536
    Thanks
    22
    Thanked 37 Times in 31 Posts
    Of course, but accelerator was only asking for something quick & simple. I just assumed that he wanted to use it as a one-off

  7. #6
    a4uDarian's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2008
    Posts
    199
    Thanks
    19
    Thanked 43 Times in 30 Posts
    Yeh indeed, the warning was mostly for future people who may not know better yet. I can imagine someone simply copy pasting, it working and then them not thinking any more about it. Mostly from experience

  8. #7
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,008
    Thanks
    54
    Thanked 180 Times in 161 Posts
    I'm using it in the admin section of my site, behind htaccess password protection, so it should be ok. Thanks for your concern though.

    Rgds

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multi site upload script For Sale
    By KPR in forum Domains & Websites For Sale
    Replies: 0
    Last Post: 08-02-09, 10:52 PM
  2. simple countdown script needed
    By affiliatemarketingltd in forum Programming
    Replies: 7
    Last Post: 12-11-08, 11:42 PM
  3. Recommend a simple gif creator?
    By D-Mac in forum Affiliate Marketing Lounge
    Replies: 3
    Last Post: 28-05-08, 05:22 PM
  4. php, image upload, resize, resample and crop
    By morleymouse in forum Programming
    Replies: 2
    Last Post: 11-01-06, 09:59 PM
  5. Photo upload and rating script?
    By stevenm in forum Programming
    Replies: 1
    Last Post: 16-12-05, 02:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2