php视频上传
php视频上传
视频上传与文件上传,其基本原理都是一样的,视频也是一种文件;要上传视频是需要前后端配合处理的,直接上代码
前端页面:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset=gb2312>
<title>上传视频</title>
</head>
<body>
<form action="demomp3.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
<input type="file" name="upfile" size=20>
<input type="submit" value="上传视频">
</form>
</body>
</html>
后端demomp3.php代码:
<?php
$upfile = $_FILES['upfile'];
function upload_file($files, $path='./upload', $fileext=['jpg','gif','png','jpeg','mp4']){
//判断错误号
if(@$files['error'] == 00) {
//判断文件类型
$ext = strtolower(pathinfo(@$files['name'], PATHINFO_EXTENSION));
if(in_array($ext, $fileext)){
return "非法文件类型";
}
//判断是否存在上传到的目录
if(!is_dir($path)){
mkdir($path, 0777, true);
}
//生成唯一文件名
$filename = md5(uniqid(microtime(true), true)).'.'.$ext;
//将文件名拼接到指定目录
$destname = $path."/".$filename;
//移动文件
if(!move_uploaded_file($files["tmp_name"], $destname)){
return "文件上传失败!";
}
return "文件上传成功!";
}else{
//根据错误号返回提示信息
switch(@$files["error"]){
case 1:
echo "上传文件超过了php.ini中upload_max_filesize选项限制值";
break;
case 2:
echo "上传文件超过了HTML表单中MAX_FILE_SIZE限制值";
break;
case 3:
echo "文件只有部分被上传";
break;
case 4:
echo "没有文件被上传";
break;
case 6:
case 7:
echo "系统错误";
break;
}
}
}
echo upload_file($upfile);