php上传上传文件时出错

I am unable to upload any file to my website.

Is my code wrong? In addition I wanted to know the php code for setting the maximum upload size for the files I wanted to upload to a Server. Also how I am supposed to change my file upload maximum size in my XAMPP, I am using version 1.7.3.

This is my code:

<?php 
//Load the settings
require_once("Setting.php");
require_once("db.php");
$message = "";
//Has the user uploaded something?
if(isset($_FILES['file']))
{
    $_FILES['file']['tmp_name'];
    $target_path = Setting::$uploadFolder;  
    $target_path = $target_path . time() . '_' . basename( $_FILES['file']['name']); 
    echo $target_path;

        //Try to move the uploaded file into the designated folder
        if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) 
        {
            $message = "The file ".  basename( $_FILES['file']['name']). " has been uploaded";

            $query ="insert into upload (path) values ('$target_path')";

        $dbresult = mysql_query($query,$dblink);

        } else{
            $message = "There was an error uploading the file, please try again!";
        }
    }

    //Clear the array
    unset($_FILES['file']);

if(strlen($message) > 0)
{
    $message = '<p class="error">' . $message . '</p>';
}

/** LIST UPLOADED FILES **/
$uploaded_files = "";

//Open directory for reading
$dh = opendir(Setting::$uploadFolder);

//LOOP through the files
while (($file = readdir($dh)) !== false) 
{
    if($file != '.' && $file != '..')
    {
        $filename = Setting::$uploadFolder . $file;
        $parts = explode("_", $file);
        $size = formatBytes(filesize($filename));
        $added = date("m/d/Y", $parts[0]);
        $origName = $parts[1];
        $filetype = getFileType(substr($file, strlen($file) - 3));
        $uploaded_files .= "<li class=\"$filetype\"><a href=\"$filename\">$origName</a> $size - $added</li>
";
    }
}
closedir($dh);

if(strlen($uploaded_files) == 0)
{
    $uploaded_files = "<li><em>No files found</em></li>";
}

function getFileType($extension)
{
    $images = array('JPG', 'GIF', 'PNG', 'BMP');
    $docs   = array('TXT', 'RTF', 'DOC');
    $apps   = array('ZIP', 'RAR', 'EXE');

    if(in_array($extension, $images)) return "Images";
    if(in_array($extension, $docs)) return "Documents";
    if(in_array($extension, $apps)) return "Applications";
    return "";
}

function formatBytes($bytes, $precision = 2) { 
    $units = array('B', 'KB', 'MB', 'GB', 'TB'); 

    $bytes = max($bytes, 0); 
    $pow = floor(($bytes ? log($bytes) : 1024) / log(1024)); 
    $pow = min($pow, count($units) - 1); `enter code here`

    $bytes /= pow(1024, $pow); 

    return round($bytes, $precision) . ' ' . $units[$pow]; 
} 
?>

Does it fall on your if statement if(isset($_FILES['file']))?

if not better check your html tag and check if there is an enctype="multipart/form-data" in it.

Your final code would look like this

<form method="POST" action="submit.php" enctype="multipart/form-data">
<!-- Your HTML form -->
</form>

About changing the size of file upload: Just open your php.ini located in /xampp/php/php.ini. Find and change the following:

upload_max_filesize

post_max_size

Just type 50M.

To upload any file firstly, ensure that PHP is configured to allow file uploads. check file

/opt/lampp/etc/php.ini

search for the file_uploads directive, and set this On,

file_uploads = On


for Maximum allowed size for uploaded files,you can again update the file php.ini the directives for e.g.

upload_max_filesize = 40M

post_max_size = 40M

post_max_size >= upload_max_filesize