nirosha rathnayaka
nirosha rathnayaka

Reputation: 198

Error uploading video file in php

I want to upload video files using php and the html form, the php code and the error as follows.

I can upload almost any other file type (image, zip, text etc after changing relevant code) except videos (.mp4, .flv, .avi).

UPDATE: I've uploaded the form as an image: enter image description here

 <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"/>

saveVideo.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..

Error:

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

I've used the same code (with image attributes) for image upload and it worked perfectly. But when uploading video this gave me lot of errors and some are corrected. Now I can't get the post data from the form in to the saveVideo.php (I checked the 7th and 14th line but no success).

Thanks in advice.

Upvotes: 0

Views: 3608

Answers (2)

Daedalus
Daedalus

Reputation: 7722

For the life of me, I can't really figure out what's wrong here. I do have a suggestion though, and that is to upgrade your installation of XAMPP to the latest version. Usually upgrading fixes whatever bugs are present in the previous install. I am myself currently running on 1.8.1, and was unable to reproduce your error, so maybe if you upgrade, it will fix whatever was amiss.

Upvotes: 1

Kiran
Kiran

Reputation: 921

What size files you are trying to upload . PHP has certain File Upload size limit. If the uploaded files exceeds this limit, will give blank data from the $_FILES array . Check your php.ini 's file uploads section for the size limit, also check post max size . By default the size will be 2 MB , you can increase and restart server .

Try this

Upvotes: 2

Related Questions