【发布时间】:2013-01-25 00:28:52
【问题描述】:
我想用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 行但没有成功)。
感谢您的建议。
【问题讨论】:
-
所以?为什么没有定义 txtCardNo?
-
@nirosharathnayaka 那是因为你没有在代码块之前放置一个空行。一张照片会让你被否决更多,因为它无济于事。
-
我已经在 标签中输入了表单。但它没有出现。因此我上传了与图片相同的内容。
-
你怎么知道电影是mp4文件?
-
此时我唯一可以推荐的就是升级您的安装。我无法复制您的问题。