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

when we submit any string in single inverted comma('abc') with get or post method,we will get exact string with single inverted comma('abc')by using $_REQUEST[]. But it is giving (\'abc\'). so anybody please help me to remove that slash,therefore i will get exact string...

2 Answers  


How to create connection in php?

0 Answers  


Tell me how is it possible to know the number of rows returned in result set?

0 Answers  


How to find second highest salary

9 Answers  


What are session variables in php?

0 Answers  






How to check whether a number is prime or not?

0 Answers  


What is the difference between query and question?

0 Answers  


Do you know how can php and html interact?

0 Answers  


What are the security measures we have to take for our site not to hack by others?

1 Answers   Infosys,


What are php magic methods/functions?

0 Answers  


How can we encrpt a text?

3 Answers  


Explain what are the three classes of errors that can occur in php?

0 Answers  


Categories