Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP获取mimetype不工作的文档_Php_Upload - Fatal编程技术网

PHP获取mimetype不工作的文档

PHP获取mimetype不工作的文档,php,upload,Php,Upload,我只想上传图片,文件上说使用finfo_open。 我这样做了,但我得到了以下错误: 致命错误:在中调用未定义的函数finfo_open() 第83行调用堆栈上的C:\xampp\htdocs\ticket\index.php 时间内存函数位置1 2.2551 158752{main}()..\index.php:0 PHP: if(isset($\u文件['file'])){ $finfo=finfo\u open(FILEINFO\u MIME\u类型); $ext=finfo_file(

我只想上传图片,文件上说使用finfo_open。

我这样做了,但我得到了以下错误:

致命错误:在中调用未定义的函数finfo_open() 第83行调用堆栈上的C:\xampp\htdocs\ticket\index.php

时间内存函数位置1 2.2551 158752{main}()..\index.php:0 PHP:

if(isset($\u文件['file'])){
$finfo=finfo\u open(FILEINFO\u MIME\u类型);

$ext=finfo_file($finfo,$_FILES['file']['name']);PHP5.3.0及更高版本内置了Fileinfo,但在Windows上,必须在PHP.ini中手动启用它

查看php.ini文件并检查fileinfo.so或php_fileinfo.dll是否已激活(取决于您的平台和版本)

应该有一条类似于

extension = fileinfo.so
在窗户上

extension = fileinfo.dll
在php.ini文件中

更新后

使用['file']['tmp_name']作为路径(需要路径!)


finfo_open need PHP>=5.3.0我有:PHP版本5.4.7检查PHP.ini fileinfo.so是否是活动的,但现在我得到了:警告:finfo_文件(download.jpg):无法打开流:在第84行调用堆栈#时间内存函数位置1 2.2531 158448{main}()..\index.php:0 2 3.2572 180560 finfo_文件()..\index.php:84
extension = fileinfo.dll
if(isset($_FILES['file'])) {
    $finfo = finfo_open(FILEINFO_MIME_TYPE); 
    $ext = finfo_file($finfo, $_FILES['file']['tmp_name']);

    if(substr($ext, 0, 5) != 'image') {
       $errors[] = 'Kon dit bestand type niet uploaden.';
    }
}