PHP文件上载中支持的文件类型有哪些?

What are the supported file types in php file upload?

   Choose a file to upload: <input name="uploadedfile" type="file" />
   <br />
      Username:<input type="text" name="username">
   <br />
      Password:<input type="text" name="password">
   <br />
      FaxNumber:<input type="text" name="faxnumber">

   <input type="submit" value="Upload File" />

by default: nearly anything you want (pdf,txt,exe,jpg) etc.

Its your job to filter out anything you do wish to use. you can filter against anything inside $_FILES array(type,size) etc

PHP does not limit anything like this. A file is always just data. PHP gives you that data when it's "posted" (or uploaded) to your server. It doesn't look at it to determine what kind of data it is, it's really just saying "this data was uploaded, here's the path to the temporary file." Anything is acceptable to PHP, as long as your server can handle receiving the entire file. Whether or not you want to limit what types can be uploaded is completely up to you.

PHP will support all file types for file upload, But you have to validate for some file extensions which can hack your site and also you have to consider file size to avoid long running script.

There is no limit client side, all files/types are supported. PHP, also, has no built in limits and supports all files. If you want to limit what can be uploaded in php it looks something like the following snippet, Which limits the file to a gif image:

if ($_FILES["file"]["type"] == "image/gif"){
    //do stuff here
}
else{
    //the file was wrong type handle error here
}

You can find a list of MIME types, "image/gif" in the above code, at:
http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types

PHP does not handle uploads. Uploads are supported by the http specification, and should be handled by your webservice (Apache, IIS, etc).

Regardless, if you wish to just save the uploaded file, then all file types should work fine. If you want to process the uploaded file as input, things get much more hairy.

Maybe you need this : http://en.wikipedia.org/wiki/Internet_media_type

There is no limit on file type by default,till you specify a restriction.

The file type of an uploaded file is available by :

$_FILES['yourFileName']['type']

You can upload any file, php doesn't limit it. You self need to do the restrict.

For client file format limit, refer to this Limit file format when using ?

<input type="file" accept="image/*" /> <!-- all image types --> 
<input type="file" accept="audio/*" /> <!-- all audio types --> 

For server, you can filter the uploaded file by this,

if(in_array(mime_type($file_path),$allowed_mime_types)){
    // save the file
}

$allowed_mime_types = array(
        'image/jpeg',
        'image/jpg',
        'image/png',
        'image/gif',
        'video/mp4'
);


/*
For PHP>=5.3.0, you can use php's `finfo_file`([finfo_file](https://www.php.net/manual/en/function.finfo-file.php)) function to get the file infomation about the file.

For PHP<5.3.0, you can use your's system's `file` command to get the file information.
*/
function mime_type($file_path)
{
    if (function_exists('finfo_open')) {            
        $finfo = new finfo(FILEINFO_MIME_TYPE, null);
        $mime_type = $finfo->file($file_path);
    }
    if (!$mime_type && function_exists('passthru') && function_exists('escapeshellarg')) {
        ob_start();
        passthru(sprintf('file -b --mime %s 2>/dev/null', escapeshellarg($file_path)), $return);
        if ($return > 0) {
            ob_end_clean();
            $mime_type = null;
        }
        $type = trim(ob_get_clean());
        if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\.]+)#i', $type, $match)) {
            $mime_type = null;
        }
        $mime_type = $match[1];
    }
    return $mime_type;
}
</div>