Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: Why am I getting this error?

  1. #21
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    Okay so I got it to say the correct things with someone uploads a file but requardless of the file name the file still uploads even though it says it is the wrong file type
    ___________________________________

    Still working on it!

  2. #22
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    PHP Code:
         $userfile $_FILES['action_id']['name'];
        
    $file_size $_FILES['action_id']['size'];
        
    $file_temp $_FILES['action_id']['tmp_name'];
        
    $file_err $_FILES['action_id']['error'];
        
    $path '../../downloads/photoshop/temp_actions/';
        
                
    // limit the size of the file to 20MB
        
    if($file_size 20971520) {
            echo 
    '<font color="#F0B80F"><b>The file you are trying to upload is too large. Please restrict your file to at least 20MB </b></font><BR />';
            exit();
        }
        
        
    // Create a new file name
        // This is so if other files on the server have the same name, it will be renamed
        
    $randomizer rand(0099);
        
    $file_name $randomizer'_' .$userfile;
        
        
    // Get the file type
        // Using $_FILES to get the file type is sometimes inaccurate, so we are going
        // to get the extension ourselves from the name of the file
        // This also eliminates having to worry about the MIME type
        
    $file_type $userfile;
        
    $file_type_length strlen($file_type) - 3;
        
    $file_type substr($file_type$file_type_length);

        if(!empty(
    $userfile)) {
            echo 
    'File Uploaded Information
            <ul>
            <li>File being uploaded: ' 
    .$userfile'</li>
            <li>File Type: .' 
    .$file_type.'</li>
            <li>File Size: ' 
    .$file_size' KB </li>
            <li>File Error: ' 
    $file_err'</li>
            </ul>'
    ;


            
    $errors = array(); // Initialize an errors array
            
            // Set allowed file types
            // Set case of all letters to lower case
            
    $file_type strtolower($file_type);
            
    $files = array("atn"); // Allowed file extensions
            
    $allowed_type = array("text/plain""application/msword""application/pdf"); 

            
    // Search the array for the allowed file type
            
    $ext strtolower(substr($userfilestrrpos($userfile'.') + 1));

                if ( !
    in_array($ext$files) ) { // Check for allowed file extension
                
                
    $errors[] = '<font color="#F0B80F"><b>The file you are trying to upload has the wrong extension.';

              }
              

    if ( empty(
    $errors) ) { // If the errors array is empty, there are no errors, so upload
        
        // UPLOAD THE FILE
        
    echo 'Thank you for your contribution. <br>You should see your action on the site within 24 hours.';
     }

    if ( !empty(
    $errors) ) { // Check to see if there were errors and echo them to the user
        
        
    foreach ( $errors as $error ) {
            echo 
    $error ' Please choose another file. </b></font><br />';
            
        }
        
    }
              
              
        
    #        echo '<b>The file you are uploading is allowed. </b><br />';
         #   } else {
          #      echo '<font color="#F0B80F"><b>The file you are attempting to upload has the wrong extension. </b></font><br />';
           #     exit();
            #}

    // Check for errors and upload the file
    $error_count count($file_error);
    if(
    $error_count 0) {
            for(
    $i 0$i <= $error_count; ++$i) {
                echo 
    $_FILES['action_id']['error'][$i];
            }
    } else {
            if(
    move_uploaded_file($file_temp'../../downloads/photoshop/temp_actions/' .$file_name.'')) {
                echo 
    '';
            } else {
                echo 
    '<font color="#F0B80F"><b>Whoops look like there was a mistake during your upload. Please try again.</b></font>';
            }
    }

        } else {
            echo 
    '<font color="#F0B80F"><b>No file has been selected.</b></font>';
        } 
    ___________________________________

    Still working on it!

  3. #23
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Quote Originally Posted by Dirt_Diver View Post
    Are you saying that I'm useless with out you??? hahaha

    BTW I have the book.
    I was just trying to help.

    If you have the book, read it. They do exactly what you are trying to do here. Good luck.

  4. The Following User Says Thank You to JasonDFR For This Useful Post:

    Dirt_Diver (02-24-2009)

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
  •