Reputation: 81
I have a form which has textboxes and has certain values. and i have a video upload file in that form. I am using move_uploaded_file function in which i am successfully uploading the Video File to DB and storing in a Specific folder and displaying as Thumbnail in a form.
Again i am successfully Updating the video file which is replaced in DB and also storing in the folder.
Scenario is - While updating, if i do not select any video to update, Empty values are going. and getting Object not found.
Here the updating the video is not mandatory, So if i am not selecting any video, It should retain my previous video file and should display.
Here is My Update Form Code
<form id="My_Form" action="currentpage.php" method="post" enctype="multipart/form-data">
<input type="file" id="Edit_Vid" name="Edit_Vid">
<?php
$output_dir = "houseadvideos/";
if(isset($_FILES["Edit_Vid"]))
{
if($_FILES["Edit_Vid"]["error"] > 0)
{
$result['error'] = "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
move_uploaded_file($_FILES["Edit_Vid"]["tmp_name"],$output_dir. $_FILES["Edit_Vid"]["name"]);
$result['success'] = "Uploaded Document :".$_FILES["Edit_Vid"]["name"];
}
}
else{
$result['error'] = 'upload document';
}
?>
</form>
Code to Update DB Value
function UpdateForm($id,$name,$type,$dimension,$video,$duration,$uploaddate){
if(!$this->DBLogin())
{
$this->HandleError("Database login failed!");
return false;
}
$a=$varArray['upvid'];
$file = str_replace( "\\", '/', $a );
$ofile = basename( $file );
$oofile ="myfolder/".$ofile;
$date = date('m/d/Y', time());
$qry ="update column_name set name='$name',type='$type',dimension='$dimension',video='$video',duration='$duration' where id=$id";
$result = mysql_query($qry,$this->connection);
return $result;
}
Thanks in advance
Upvotes: 0
Views: 150
Reputation: 863
Controller model binding:
$pathToVideo = '';
if(is_uploaded_file($_FILES["Edit_Vid"]["tmp_name"])) {
move_uploaded_file($_FILES["Edit_Vid"]["tmp_name"],$outp.. and so on
//store in database
$pathToVideo = 'the new path';
} else {
//update model with last inserted video in database
//SELECT FROM table WHERE user.. ODER BY ID DESC LIMIT 1,0
$pathToVideo = 'the old path';
}
//serialize your updated video path back
//render form with updated model
Edit after comment (how to get last video record)
function GetLastVideoRecord() {
$qry ="SELECT * FROM column_name ORDER BY ID DESC LIMIT 1,0";
$result = mysql_query($qry, $this->connection);
$row = mysql_fetch_assoc($result);
return $row[0];
}
Upvotes: 1