我想使用php和html表单上传视频文件,php代码和错误如下。
除了视频(.mp4、.flv、.avi)之外,我几乎可以上传任何其他文件类型(图像、zip、文本等),除非是视频(.mp4、.flv、.avi)。
更新:我已将表格作为图片上传:
<form enctype="multipart/form-data" action="saveVideo.php" method="post" >
<input type="text" name="txtCardNo" size="6" maxlength="6"autofocus required/>
<input type="file" name="video" required/>
<input type="hidden" name="MAX_FILE_SIZE" value="26214400" />
<input type="submit" value="Submit" class="ok"/>
保存视频.php:
require_once('config.php');
// get info from the form
$card = trim($_POST['txtCardNo']); //7th line (error 1)
// directory where Videos will be saved
$target = "videos/";
$target = $target . basename($card . ".mp4"); //rename the video
$video = $card . ".mp4"; //name saved in the db
echo $_FILES["video"]["type"]; //14th line (error 2)
if ($_FILES["video"]["type"] == "video/mp4"){ //check for .mp4
if ($_FILES['video']['size'] > $_POST['MAX_FILE_SIZE']){ //check file size
$_SESSION['error'] = "Video size should be less than 25MB.!";
}else{
$check = mysql_query("SELECT SN FROM Videos WHERE CardNo = '$card'"); //check for existing image
if (mysql_num_rows($check) < 1){
$sql_query = "INSERT INTO Videos (CardNo, Video, Date) VALUES ('$card', '$video', NOW())";
}else{
$sql_query = "UPDATE Videos SET CardNo ='$card', Video = '$video', Date = NOW() WHERE CardNo = '$card' LIMIT 1";}
if(mysql_query($sql_query, $dbLink) or die(mysql_error())){
if(move_uploaded_file($_FILES['video']['tmp_name'], $target)){ //move video to videos folder
$_SESSION['error'] = "The file ". basename( $_FILES['video']['name']). " uploaded successfully.!";
}else {
$_SESSION['error'] = "Error moving record.!"; }
}else{
$_SESSION['error'] = "Error updating record.!"; }}
}else{
$_SESSION['error'] = "Invalid file type. Allowed only .mp4, video format.!";
} etc..
错误:
Notice: Undefined index: txtCardNo in C:\xampp\htdocs\video\saveVideo.php on line 7
Notice: Undefined index: video in C:\xampp\htdocs\video\saveVideo.php on line 14
我使用相同的代码(带有图像属性)进行图像上传,并且效果很好。但是在上传视频时,这给了我很多错误,其中一些已得到纠正。现在我无法将表单中的帖子数据输入到 saveVideo.php 中(我检查了第 7 行和第 14 行但没有成功)。
谢谢指教。