1

我做了简单的功能:



    function get($field, $dir = 'dir/') {
            $file_tmp = $_FILES[$field]['tmp_name'];
            $file_name = $_FILES[$field]['name'];
            $file_size = $_FILES[$field]['size'];
            $ext = explode(".", $file_name);
            $ext = $ext[1];
            if ($ext != 'xml') {
                if (is_uploaded_file($file_tmp)) {
                    move_uploaded_file($file_tmp, $dir . $file_name);
                    echo "file: 
                      $file_name size:  
                      $file_size done !
                      ";
                } else {
                    echo "Possible file upload attack: ";
                    echo "filename '" . $file_tmp . "'.";
                }
            } else {
                move_uploaded_file($file_tmp, $dir . $file_name);
                echo "file: 
                      $file_name size:  
                      $file_size done !
                      ";
            }
        }


函数将文件上传到服务器(例如 .jpg、.gif),但是当我尝试上传 .xml 时出现问题并且文件不上传。这是为什么?

4

1 回答 1

0

像这样尝试,然后检查发生了什么:

function get( $field, $dir = 'dir/' )
{
    $file_tmp = $_FILES[$field]['tmp_name'];
    $file_name = $_FILES[$field]['name'];
    $file_size = $_FILES[$field]['size'];
    $ext = explode( ".", $file_name );
    $ext = $ext[1];

    if ( $ext != 'xml' ) {
        if ( is_uploaded_file( $file_tmp ) ) {
            move_uploaded_file( $file_tmp, $dir . $file_name );
            echo "file: $file_name size: $file_size done ! ";
        } else {
            echo "Possible file upload attack: ";
            echo "filename '" . $file_tmp . "'.";
        }
    } else {
        if ( is_uploaded_file( $file_tmp ) ) {
            move_uploaded_file( $file_tmp, $dir . $file_name );
            echo "file: $file_name size: $file_size done !";
        } else {
            echo "There was a porblem, check error.log";
        }
    }
}

此外,wamp 服务器上文件上传的默认限制为 2MB,请尝试增加该值。

于 2013-11-11T13:36:17.297 回答