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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an operator in php?

564


What is the use of die in php?

515


What is the use of friend function in php?

528


How to protect special characters in query string?

524


What is csrf token and how will you add csrf token in ajax?

517






What is cURL in PHP?

542


How do I find environment variables?

500


What is the meaning of a persistent cookie?

554


What is super () python?

527


What is the difference between file_get_contents() and file_put_contents() in php?

671


Why does php need server?

515


What is substr() in php? And how it is used?

517


How can I find my php version?

536


Which function is used to read a file removing the html and php tags in it upwork?

482


What are the array functions in php?

518