我正在尝试在我的项目中使用php类插件。 (Windows)中
https://github.com/mhor/php-mediainfo
这是一个非常基本的问题,但我不知道如何使这项工作。
我的代码:
<?php
include '/mediainfo/MediaInfo.php';
$mediaInfo = new MediaInfo();
我收到了这个错误:
Fatal error: Class 'MediaInfo' not found in index.php on line 15
/mediainfo/MediaInfo.php:
<?php
namespace Mhor\MediaInfo;
use Mhor\MediaInfo\Builder\MediaInfoCommandBuilder;
use Mhor\MediaInfo\Container\MediaInfoContainer;
use Mhor\MediaInfo\Parser\MediaInfoOutputParser;
class MediaInfo
{
/**
* @param $filePath
* @return MediaInfoContainer
*/
public function getInfo($filePath)
{
$mediaInfoCommandBuilder = new MediaInfoCommandBuilder();
$output = $mediaInfoCommandBuilder->buildMediaInfoCommandRunner($filePath)->run();
$mediaInfoOutputParser = new MediaInfoOutputParser();
$mediaInfoOutputParser->parse($output);
return $mediaInfoOutputParser->getMediaInfoContainer();
}
}
我不知道'Mhor \ MediaInfo'。我刚刚从Github下载了源代码并将其解压缩到根www / mediainfo:
我尝试了其他一些类并得到了同样的错误。
在尝试了Tanmay Kumar的建议之后:$mediaInfo = new \Mhor\MediaInfo\MediaInfo();
错误已修复,但下一行:
$mediaInfoContainer = $mediaInfo->getInfo('video.mp4');
给出:
Fatal error: Class 'Mhor\MediaInfo\Builder\MediaInfoCommandBuilder' not found
答案 0 :(得分:1)
将$ mediaInfo替换为: -
$mediaInfo = new \Mhor\MediaInfo\MediaInfo();
答案 1 :(得分:0)
以下是完整正确的方法:
include '/mediainfo/MediaInfo.php';
use \Mhor\MediaInfo\MediaInfo;//now you can directly call class on it's name
$mediaInfo = new MediaInfo();
如果您再遇到问题,请告诉我们。)