How to upload any files extension in our database
Ex.(.doc,.txt,mp4,mp3 etc.)in php



How to upload any files extension in our database Ex.(.doc,.txt,mp4,mp3 etc.)in php..

Answer / rajasekhar

It is so simple

first take a form to upload any extension file, your self

<?php
if($_POST['submit'] == 'submit')
{
$filename = $_FILES['file']['name'];
$tmpname = $_FILES['file']['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['file']['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'];
}
?>


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

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More PHP Interview Questions

How do I run a php program in dreamweaver?

0 Answers  


Tell us how to set cookies in php?

0 Answers  


What is cookies php?

0 Answers  


How can image properties be retrieved in php?

0 Answers  


What are the methods of array in java?

0 Answers  






What types of images that PHP supports?

2 Answers  


Write syntax to open a file in php?

0 Answers  


what does this symbol mean in php?

0 Answers  


How can we take a backup of a mysql table and how can we restore it. ?

7 Answers   Brain Infosys, Oracle,


How can you insert javascript in php code?

13 Answers   TCS,


armstrong number by using php while number is given by the keyboard.?

0 Answers  


sort term descripttion form, report and uery

0 Answers  


Categories