$_FILES['*']['type'] doesn't get type

Discussion in 'PHP' started by moheballah, Jul 11, 2008.

  1. #1
    hi,

    all scripts that using this function $_FILES['*']['type'] to get type of file and compare it with allowed extention are failed to upload

    so i written a simple code to get information of uploaded file

    <?php
    
    
    echo ini_get("file_uploads");
    
    if ( isset($_POST['send']) )
    {
        if(!$_FILES['File1']['name'])
            echo "error";
        else
        {
            echo '<pre>';
            print_r($_FILES);
            echo'</pre>'; 
    
        }
    }
    
    else
    {
        echo "<form method='post' enctype='multipart/form-data' action='test.php'>    
        <input name='File1' type='file' />
        <input name='send' type='submit' value='submit' /></form>";
    }
    
    
    PHP:
    the output of this code is

    1
    
    Array
    (
        [File1] => Array
            (
                [name] => test.gif
                [type] => 
                [tmp_name] => 
                [error] => 1
                [size] => 0
            )
    
    )
    
    PHP:
    i tried to
    * change my browser
    * delete htaccess file
    * change max_execution_time

    but it still exist
     
    moheballah, Jul 11, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    What type of file are you uploading, is it a valid gif?

    Tested this locally with a jpeg and got this result:
    
    Array
    (
        [File1] => Array
            (
                [name] => t1126892861_8134.jpg
                [type] => image/jpeg
                [tmp_name] => C:\server\tmp\php586.tmp
                [error] => 0
                [size] => 1031
            )
    
    )
    Code (markup):
    Looking at your results... [error] => 1 gives a lot away.

    Add this code to the top of your page:
    error_reporting(E_ALL);
    PHP:
    and tell me any response. E.g. is tmp read/writable?

    Dan
     
    Danltn, Jul 11, 2008 IP
  3. moheballah

    moheballah Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    every file i tried to upload i get same error
    i mailed support of server and them try to solve it

    1
    
    Array
    (
        [File1] => Array
            (
                [name] => 52202_1211219927.jpg
                [type] => 
                [tmp_name] => 
                [error] => 1
                [size] => 0
            )
    
    )
    
    PHP:
    i don't know they can solve it or not
    this error happen after upgrade php to php 5
     
    moheballah, Jul 11, 2008 IP
  4. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    They probably forgot to set the file upload_tmp_dir in the php.ini

    do an ini_get('upload_tmp_dir'); and check
     
    Mozzart, Jul 11, 2008 IP
  5. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Use this <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
     
    NatalicWolf, Jul 11, 2008 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    Either the tmp directory is not set, the max upload size is too small or allow file upload is off.

    Peace,
     
    Barti1987, Jul 11, 2008 IP
  7. moheballah

    moheballah Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    server support solved the problem
    thanks all
     
    moheballah, Jul 11, 2008 IP