html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<caption>视频上传/展示</caption>
<thead>
<td>
<form enctype="multipart/form-data" method="post" action="upload">
<input type="file" name="file" placeholder="点击选择文件">
<input type="submit" value="上传视频">
</form>
</td>
</thead>
</table>
</body>
</html>
PHP代码
public function upload()
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
$dirPath = 'upload/';//设置文件保存的目录
if (!is_dir($dirPath)) {
//目录不存在则创建目录
@mkdir($dirPath);
}
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
生成缩略图需要下载ffmpeg 插件
可自行上网下载或于 https://download.csdn.net/download/qq_29099209/10316770 下载
composer 下载依赖库
composer require php-ffmpeg/php-ffmpeg
在composer.json文件中添加
"php-ffmpeg/php-ffmpeg": "^0.11.1"
安装成功即可使用
use FFMpeg\Coordinate\TimeCode;
use FFMpeg\FFMpeg;
+use FFMpeg\Coordinate\Dimension;
$ffmpeg = FFMpeg::create(array(
'ffmpeg.binaries' => 'D:\phpStudy\php\php-7.0.12-nts\ffmpeg\bin\ffmpeg.exe',//插件下载地址
'ffprobe.binaries' => 'D:\phpStudy\php\php-7.0.12-nts\ffmpeg\bin\ffprobe.exe',
//linux 下
//'ffmpeg.binaries' => '/opt/local/ffmpeg/bin/ffmpeg',
//'ffprobe.binaries' => '/opt/local/ffmpeg/bin/ffprobe',
'timeout' => 0,
'ffmpeg.threads' => 12
));
$video = $ffmpeg->open("upload/".$_FILES["file"]["name"]);
$video->frame(TimeCode::fromSeconds(20))->save('frame.jpg');
$video->gif(TimeCode::fromSeconds(20),new Dimension(300,400),100)->save('upload/frame1.gif');
码云下载链接:https://gitee.com/wjhee/VideoUpload
最终截图成功!快来试试吧