+ Reply to Thread
Results 1 to 7 of 7
  1. Join Date
    Nov 2004
    Location
    England
    Posts
    2,291
    Thanks
    40
    Thanked 138 Times in 122 Posts

    Recommend Me a Simple PHP Image Upload Script

    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. Join Date
    Jan 2008
    Location
    Pangaea
    Posts
    644
    Thanks
    22
    Thanked 35 Times in 29 Posts

    Re: Recommend Me a Simple PHP Image Upload Script

    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. Join Date
    Nov 2004
    Location
    England
    Posts
    2,291
    Thanks
    40
    Thanked 138 Times in 122 Posts

    Re: Recommend Me a Simple PHP Image Upload Script

    Thanks for that.

    Rgds

  5. Join Date
    Aug 2008
    Posts
    130
    Thanks
    11
    Thanked 34 Times in 23 Posts

    Re: Recommend Me a Simple PHP Image Upload Script

    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. Join Date
    Jan 2008
    Location
    Pangaea
    Posts
    644
    Thanks
    22
    Thanked 35 Times in 29 Posts

    Re: Recommend Me a Simple PHP Image Upload Script

    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. Join Date
    Aug 2008
    Posts
    130
    Thanks
    11
    Thanked 34 Times in 23 Posts

    Re: Recommend Me a Simple PHP Image Upload Script

    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. Join Date
    Nov 2004
    Location
    England
    Posts
    2,291
    Thanks
    40
    Thanked 138 Times in 122 Posts

    Re: Recommend Me a Simple PHP Image Upload Script

    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

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, 04: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

Content Relevant URLs by vBSEO 3.5.0 RC1 PL1