Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Why am I getting this error?

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

    Default Why am I getting this error?

    I'm trying to upload a file and it's telling me I have the wrong extension.

    Now I'm blocking everything but the extension but I'm giving it the right file and it's not allowing it through, why??

    The file I am tring to upload is
    C:\Users\me\my file.atn

    The error I am getting is:
    The file you are attempting to upload has the wrong extension.


    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/';
        
        
    // Create a new file name
        // This is so if other files on the server have the same name, it will be renamed
        
    $randomizer rand(00009999);
        
    $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>'
    ;

            
    // 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();
            }

            
    // Set allowed file types
            // Set case of all letters to lower case
            
    $file_type strtolower($file_type);
            
    $files = array();
            
    $files[] = 'atn'
            
    $files[] = 'aaa'
            
    $files[] = 'bbb'
            
    // Search the array for the allowed file type
            
    $key array_search($file_type$files);
            if(
    $key) {
                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 
    'Thank you for your contribution. You should see your action on the site within 24 hours.';
            } 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!

  2. #2
    Join Date
    Jul 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    hi...
    i think its file name problem...

    ur file name having space in the middel of the name...

    (or)

    where u mentioned ur file extentions.....atn is not the file extention(what i know)...try ro check again..

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

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

    Default

    So because windows doesn't know the file, php can't process it?
    ___________________________________

    Still working on it!

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

    Default

    I just tried to change the extensions allowed to a jpg and tried to upload a jpg and I got the same error.
    I even tried to

    PHP Code:
    $files[] = 'image/jpg'
    still not working
    ___________________________________

    Still working on it!

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Its jpeg.
    Jeremy | jfein.net

  7. #7
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    If it is jpeg, then you're going to need to restructure your code - at the moment you're taking away 3 from the string to be left with the extension. That's not going to work if you have a file like jpeg which is 4 characters long =/

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

    Default

    Well I did jpg as a test just to see if it would allow the file to be uploaded. but it didnt work.

    The file I need ends with .atn,

    Is there anything wrong with the code?
    ___________________________________

    Still working on it!

  9. #9
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Try what Nile said, and make it jpeg instead of jpg.

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

    Default

    Quote Originally Posted by Schmoopy View Post
    Try what Nile said, and make it jpeg instead of jpg.

    No, .jpeg did not work. And yes I changed
    strlen($file_type) - 4;
    ___________________________________

    Still working on it!

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
  •