SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry upload a file help!!!

    ok well i have a small problem with upload file, i have code which works fine...

    but the design on my website the form which has the browse button to add the file is on page one, but i only want to upload the file on the third page when everything has been confirmed.

    HTTP_POST_FILES must store an array of values and i do not know what to pass to the last page to make it upload the file correctly. hopefully the code will make this easier to understand.

    as you can see ive tried just using the url as $source, but this didnt work!!
    think it has size, and a couple of other variables.. if i know these variables maybe i can pass these to the last page via hidden txt boxes.

    any help much appreciated!!! thanx in advance!!!

    PHP Code:

    $uploadpath 
    ''
    $source $HTTP_POST_FILES['userfile']['tmp_name']; 
    $Item_ID '786';
    //$source = 'H:\Project\htdocs\Final_Project\pictures\6824.jpg';
    $dest '';

    if ( (
    $source != 'none') && ($source != '' )) { 
            
    $imagesize getimagesize($source); 
             switch ( 
    $imagesize[2] ) { 
                case 
    0
                    echo 
    '<BR> Image is unknown <BR>'
                    break; 
                case 
    1
                    echo 
    '<BR> Image is a GIF <BR>'
                    
    $dest $uploadpath.$Item_ID.'.gif'
                    break; 
                case 
    2
                    echo 
    '<BR> Image is a JPG <BR>'
                    
    $dest $uploadpath.$Item_ID.'.jpg'
                    break; 
                case 
    3
                    echo 
    '<BR> Image is a PNG <BR>'
                    
    $dest $uploadpath.$Item_ID.'.png'
                    break; 
            } 
            
            if ( 
    $dest != '' ) { 
                if ( 
    move_uploaded_file$source$dest ) ) { 
                    echo 
    'File successfully stored.<BR>'
                } else { 
                print(
    "'"); echo $source; print("'"); echo $dest; print("'");
                    echo 
    'File could not be stored.<BR>'
                } 
            }  
        } else { 
            echo 
    'File not supplied, or file too big.<BR>'

    ?> 

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don' tthink its $HTTP_POST_FILES
    i think it should be $HTTP_FILES_VARS

    BUT i would rather use
    $_FILES
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but the design on my website the form which has the browse button to add the file is on page one, but i only want to upload the file on the third page when everything has been confirmed.
    You can't. Re-design the flow of your site. The moment you submit the form on the first page the browser will try and upload the file. It cannot be delayed to a later page.

    You could save the results of the upload somewhere on a temporary basis and then disregard them if the user doesn't complete all three steps, but the file itself will have been uploaded by then which is what I think you wanted to avoid.
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.


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
  •