我上传的文件不是移动文件夹而是路径保存在mysql中。我的代码有什么问题如何将视频保存在文件夹中,我已经创建了文件夹名称test_uploads。什么是exexct方法来获取文件夹
中的视频<?php
error_reporting(1);
$con=mysql_connect("localhost","root","");
mysql_select_db("ngo",$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 != "wmv")
{
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" style="padding:10px">
<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)
调试代码以查找错误。像这样:
$result = move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_file);
if($result) {
mysql_query("insert into video(video_name) values('$video_path')");
echo "uploaded ";
} else {
echo $_FILES["file"]["error"];
}