SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A Simple Image Uploader

    I need a simple image uploader for my website. What I need is the following...

    *A file size limit of 1mb
    *Limit file types to jpg, png and gif
    *I need the server to rename the files from 1 and up. So the first image would be named "1.jpg" for example and the 1022nd image would be named "1022.gif"

    That's all. I've looked around for image upload scripts but they're all to advanced and complicated. Could someone write me up a script for the above? I'm not sure whats involved so if it's too hard could you point me in the right direction for a tutorial or simple script like what I want?

    Cheers!

  2. #2
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're looking to have someone write a script for you, you're in the wrong forum.

    Please try http://www.sitepoint.com/forums/forumdisplay.php?f=220

  3. #3
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you can just point me in the right direction can't you? Is there a simple script out there that can do pretty much what I want above?

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should get you started if you already know some php:

    http://ca3.php.net/features.file-upload

    See also gd if you want to make thumbnails or resize the images.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  5. #5
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou

  6. #6
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ASSUME THAT FILE CONTRL WITH NAME Attachment
    PHP Code:
    if($_FILES['Attachment']['tmp_name']!='')
        {
            
    $uploadpath="../Attachment/";  // THIS IS PATH/FOLDER NAME WHRER FILE IS UPLOADED 
            
    $source=$_FILES['Attachment']['tmp_name'];
        
            
    $filename=uniqid('').$HTTP_POST_FILES['Attachment']['name'];
                   
    $uploadpath=$uploadpath.$filename;
            if((
    move_uploaded_file($source,$uploadpath)==false) && (strlen($_REQUEST['Attachment'])!=0))
            {
                echo 
    "file can not be uploaded";
                exit(
    0);
            }
        }
        else
        {
            
    $filename="";
        } 

  7. #7
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for Limit file types to jpg, png and gif u prefer javascript so that u can stop overload

  8. #8
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by simplecode
    for Limit file types to jpg, png and gif u prefer javascript so that u can stop overload


    It would be crazy to rely on javascript to filter uploads on a production website. All a hacker would have to do is disable javascript and they can upload anything they want - including .php. Javascript is useful to tell the user before they submit that the file is invalid, but the file should also be checked for security reasons and this must happen on the server.

    I don't know what you mean by stopping overload, but it is certainly less important than the site's security.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  9. #9
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes true .
    Because the code executes on the users' computer, in some cases it can be exploited for malicious purposes.
    but thats only a proposal

  10. #10
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simplecode, never, never, never!!!!!!!!!!!!!!!! do stuff like that with javascript, it's too easy manipulated.

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  11. #11
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    KoKoSNOOT
    thanks thanks thanks!!!!!!!!!!!!!!!

  12. #12
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That being said, it never hurts to use javascript to validate the filename so that the user doesnt wait 5 minutes for a file to upload only to realise that the file extension is not allowed. As long as you realize that this is to prevent annoyance and does not result in any extra security.
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.

  13. #13
    Non-Member
    Join Date
    Nov 2005
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use javascript and php. Javascript will block most uploads while php would confirm that.

    Simplecode,

    explain exactly what that code does? does it simply just uplaod the file and thats it?

    Cheers!

  14. #14
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it simply uploads the file


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
  •