move_upload_file不适用于上传视频

时间:2017-06-01 06:21:20

标签: php

我想通过表单提交上传视频(如mp4,wvm,flv),但move_file_upload()无效。

这是我的代码:

<?php
if (isset($_POST['submit'])) {
			$errors = array();
			$allowed_e = array('mp4', 'flv', 'wmv');

			$file_name = $_FILES['video2']['name'];
			$file_e = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
			$file_s = $_FILES['video2']['size'];
			$file_tmp = $_FILES['video2']['tmp_name'];
			$t_name = @$_POST['topic_name'];
			 $content = @$_POST['content'];
 			$date = date("y-m-d");
			if (in_array($file_e, $allowed_e) == false) {
			$errors[] = 'ext not allowed';
			}

			if ($file_s > 20097152) {
			$errors[] = 'File must be under 20mb';
			}
			

			if (empty($errors)) {
			$rawBaseName = pathinfo($file_name, PATHINFO_FILENAME );
		    $extension = pathinfo($file_name, PATHINFO_EXTENSION );
		    $counter1 = 1;
		    $counter2 = 1;
			    while(file_exists('video/'.$file_name)) {
			    $file_name = $rawBaseName . $counter1 . $counter2 .'.' . $extension;
			    $counter1++; 
				$counter2++;}
			move_uploaded_file($file_tmp, 'video/'.$file_name);
			$video2_up = 'video/'.$file_name;
			if ($posttopic = "INSERT INTO topics (topic_id, topic_name, topic_content, topic_creator, date, video)
	 					 VALUES ('', '".$t_name."', '".$content."', '".$_SESSION["username"]."', '".$date."', '".$video2_up."')" ){
						$conn->exec($posttopic);
					}header("Location: index.php");
							
			

			}else{
				foreach ($errors as $error) {
					echo $error, '</br>';
				}
			}

		}
?>

但是,当我删除该扩展名并允许上传一些图片时,它可以工作 请给我解决方案。

1 个答案:

答案 0 :(得分:0)

我认为问题在于文件大小。检查你的php.ini文件并增加以下php指令的限制:

post_max_size = 20M
upload_max_filesize = 20M

完成上述更改后,重新启动Web服务器。