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 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post

    Angry FILE Upload problem

    I had a working upload script... And I somehow goofed it up...

    In the addproduct function you will find
    PHP Code:
            if( !empty( $_POST['file_front'] ) ) { upload_image('file_front'$file_name "_front"); }
            if( !empty( 
    $_POST['file_back'] ) ) { upload_image('file_back'$file_name "_back"); }
            if( !empty( 
    $_POST['file_detail'] ) ) { upload_image('file_detail'$file_name "_detail"); } 
    And the upload_image function
    PHP Code:
    function upload_image($file_to_upload$new_name){

        
    define(MAX_SIZE25000);
        
    define(TARGET'coacter/static/products');
        
    //Create New File Name And Find out File Type
        
    $the_file TARGET "/" $new_name;
        
    $uploaded_type $_FILES[$file_to_upload]['type'];

        
    $file_err false;
            
        if (
    $uploaded_size MAX_SIZE){$file_err true;$exception "File size is too large. <br />";}
        
        
    //Only Allow Images//
        
    if ( !strstr$uploaded_type"image") ){ $file_err true$exception .= "This is not an image. <br />"; }
        
        
    //See if there was an error
        
    if ($file_err==true){
            print 
    $exception "< br /> Sorry, your file could not be uploaded.<br />Please Go Back!";
        }else{
        
            
    $file_split explode('.'$_FILES[$file_to_upload]['name']);
            
    $extension "." $file_split[count($file_split)-1];
            
            if(
    move_uploaded_file($_FILES[$file_to_upload]['tmp_name'], $the_file $extension)){
                print 
    "Your file was uploaded!";
            }else{
                print 
    "Sorry, there was a problem uploading your file. Please Go Back!";
            }
        }

    I tried little print statements throughout to find my problem but... I cant figure out why it isn't working. Any thoughts? I have been starting at this for HOURS..
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post
    Forgot the Error.... It tells me the file is not an image... The script was working until I put it into a function.... Not sure if that is it.. But..
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Make sure you set the enctype, and make sure the file input is named file_front or etc., and if it doesn't work post your form code(HTML).


  •  

    Posting Permissions

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