<?php
error_reporting(1);
$con=mysql_connect("localhost","root","");
mysql_select_db("demo",$con);
extract($_POST);
$target_dir = "test_upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if($upd)
{
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "mp4" && $imageFileType != "avi" && $imageFileType != "mov" && $imageFileType != "3gp" && $imageFileType != "mpeg")
{
echo "File Format Not Suppoted";
}
else
{
$video_path=$_FILES['fileToUpload']['name'];
mysql_query("insert into video(video_name) values('$video_path')");
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file);
echo "uploaded ";
}
}
//display all uploaded video
if($disp)
{
$query=mysql_query("select * from video");
while($all_video=mysql_fetch_array($query))
{
?>
<video width="300" height="200" controls>
<source src="test_upload/<?php echo $all_video['video_name']; ?>" type="video/mp4">
</video>
<?php } } ?>
<form method="post" enctype="multipart/form-data">
<table border="1">
<tr>
<Td>Upload Video</td></tr>
<Tr><td><input type="file" name="fileToUpload"/></td></tr>
<tr><td>
<input type="submit" value="Uplaod Video" name="upd"/>
<input type="submit" value="Display Video" name="disp"/>
</td></tr>
</table>
</form>
使用此代码我尝试上传视频。 视频名称已正确保存在数据库中,但问题是特定文件夹中的视频无法移动。因此,当我编写选择查询时,该时间视频不会显示。
任何人,请帮我解释一下。
我是编程语言的新手
答案 0 :(得分:0)
首先移动到文件夹,如果移动,则插入数据库。然后,检查服务器的最大上传大小。
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
mysql_query("insert into video(video_name) values('$video_path')");
echo "Uploaded successfully";
} else {
echo "Sorry, there was an error uploading your file.";
}
更改您的php.ini文件upload_max_filesize
和post_max_size
,无论您想要的大小。示例i给出100M - 100MB
; Maximum allowed size for uploaded files.
upload_max_filesize = 100M
; Must be greater than or equal to upload_max_filesize
post_max_size = 100M