Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Image/file upload doing my nut

    Does anyone have a script that will accept an image upload and saves the file to a directory. I'm looking for something in its simplest form, nothing fancy, so I can learn. So far I've found the php manual of questionable use and tutorials that plain don't work (one on phpbuilder.com).

    Any help greatly recieved.
    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    most of the ones you'll find online will be outdated due to not using the $_FILES array for variable access calls.

    PHP Code:
    $upload_error '';
    if(isset(
    $_FILES['imgref']['tmp_name']) && $_FILES['imgref']['tmp_name'] !== "none")
        {
        
    $f_type = @getimagesize($_FILES['imgref']['tmp_name']);
        if(
    $f_type[2] > 0)
            {
            
    // ftype[2] returns the filetype - where a valid image is always above zero
            // you could type test further - maybe !== 2 ~ not jpeg or somesuch.
            
    if($_FILES['imgref']['size'] < 116000)
                {
                
    // check image size in bytes
                
    move_uploaded_file($_FILES['imgref']['tmp_name'],'uploaded_images/'.$url_name_str.$_SESSION['s_id']);
                echo 
    'Your submission has been saved and our administrator will check it shortly, thankyou.<br /><br />';
                }
            else
                {
                
    $upload_error .= 'The file you uploaded was not below 116kb.<br />';
                }
            }
        else
            {
            
    $upload_error .= 'The file you uploaded was not a valid image file.<br />';
            }
        }

    $upload_error .= ($upload_error == '') ? '' '<br /><br />'
    where the input type="file" is named imgref

    should point you in the right direction anyway
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 96 Times in 94 Posts
    ug , beaten to it - but I started so I will finish ~


    PHP Code:
    <?
    function imup($path $name=''){
      if(!
    $name){
        
    $name $_FILES['infile']['name'];
      }
       
    copy($_FILES['infile']['tmp_name'], $path $name);
       
    //get some info//
       
    print_rgetimagesize($path $name) );
    }

    //if we have an uploaded file//
    if (is_uploaded_file($_FILES['infile']['tmp_name'])) {
      
    //absolute filesystem path is safest , though ../images etc should work//
      //you could add your own image name assuming you know the filetype//
      
    imup('h:/phpdev/www/' NULL);
    }
    ?>

    <form enctype="multipart/form-data" name="bella" action="<?=$_SERVER['PHP_SELF'];?>" method="POST"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="1000"> 
    Send this file: <input name="infile" type="file"> 
    <input type="submit" value="Send File"> 
    </form>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down

    My PHP is version 4.0.6, predating $_FILES

    I understand $HTTP_POST_FILES is depriciated and that $_FILES is 'autoglobal'. Otherwise what is the difference between these two? There's little info on $HTTP_POST_FILES in the manual, all attention seems to be on $_FILES...
    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 96 Times in 94 Posts
    problem is that there were security issues with the way that PHP dealt with file-uploads , hence the change ... really is time to upgrade dude
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    even on older builds you should be able to use $HTTP_POST_FILES in place of all the $_FILES calls - just run a search..replace in your fav editor.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts
    k, I'll have another bash, I'll email my host too and ask 'em if they've any plans to upgrade.
    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    No kidding that version is like 2 years old. As firepages said there have been major security fixes and enhancements done since then. If your host doesn't want to upgrade i'd find a new host.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A response within half an hour, not bad, well this is what they say...
    Hello

    We realise the security implications and that the version is some way
    behind, however, we are unable to upgrade the software before SUN
    Microsystems release the update without voiding the warranty on the
    server as such we will not do this. As soon as SUN release the package
    upgrade for the RaQ 550's it will be installed, unfortunately we do not
    know when this will be.

    Regards
    Christine
    EASILY
    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.


  •  

    Posting Permissions

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