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
What is difference between rest api and restful api?
Could we start a variable with number like $4name?
What are the advantages of triggers?
Which is variable cost?
Write a hello world program using variable?
How we load all classes that placed in different directory in one php file , means how to do auto load classes.
Php says that an array is an ordered map. But how the values are ordered in an array?
How can I prevent sql-injection in php?
How to initiate a session in php?
What is polymorphism php?
What is the integer?
How to copy a file?
Is php class name case sensitive?
How to know user has read the email-php?
What is the most convenient hashing method to be used to hash passwords?