How to Retrieve video files in php from database.....and how
to store video on database..

Answers were Sorted based on User's Feedback



How to Retrieve video files in php from database.....and how to store video on database....

Answer / dinesh

<?php
$dbhost = 'hostname';
$dbuser = 'database username';
$dbpass = ' database password';
$dbname = 'database name';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname);

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
/*
echo "<br/>".$fileName;
echo "<br/>".$fileSize;
echo "<br/>".$fileType;
//echo "<br/>".$content;
*/
$query = "INSERT INTO table_name (name, size, type, content ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');

mysql_close($conn);

echo "File $fileName uploaded";
}
?>
<form method="post" enctype="multipart/form-data">
<fieldset>
<legend> Upload Video/image</legend>
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</fieldset>
</form>

Is This Answer Correct ?    17 Yes 8 No

How to Retrieve video files in php from database.....and how to store video on database....

Answer / rajasekhar

it is same like how to store file's into database

<?php
if($_POST['submit'] == 'submit')
{
$filename = $_FILES['video']['name'];
$tmpname = $_FILES['video']['tmp_name'];
$source = "upload/"; // this is a
folder in our server or system
$distination = "upload/".$filename; // we are
uploading file in to our created folder

if($_FILES['video']['error'] == false)
{
move_uploaded_file($tmpname,$distination);
}

// using sql we are upload file name into database,
$sql = mysql_query("insert into file set filename =
'".$filename."' ");

if($sql)
{
echo "file uploaded to database successfully";
}
else
{
echo "Unable to upload file to database. ".mysql_error();
}

// Retriveing file from that database

$sql = mysql_query("select * from file");
$res = mysql_fetch_array();

echo "upload/".$res['filename']; //when you like to play
the video, you has to use Embed tag
}
?>

<form name="frm" action="<?php $_SERVER['PHP_SELF']; ?>"
method="post" enctype="multipart/form-data">
<input type="file" name="video" /><input type="submit"
name="submit" value="submit" />
</form>

Is This Answer Correct ?    17 Yes 22 No

Post New Answer

More PHP Interview Questions

What is the actually used php version?

0 Answers  


How to access a Static Member of a Class in PHP?

0 Answers  


Which function Returns the time of sunrise for a given day / location in PHP.

0 Answers  


How to redirect https to http url through .htaccess?

0 Answers  


How to store the uploaded file to the final location?

0 Answers  






Is php used anymore?

0 Answers  


What is http php?

0 Answers  


Is facebook still written in php?

0 Answers  


Is set in php?

0 Answers  


Explain me what are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

0 Answers  


What are the benefits of using queries?

0 Answers  


can any one find and tell the difference between dot net and php which one is best ? which one we get more salary? which one is stable and which one is best for freshers and also better in future and carrer ? which one we wil get more salary sir ? please send ur valuable suggestions to kiranpulsar2007@gmail.com

0 Answers  


Categories