How to Upload file in Php?
<html>
<title>File Upload</title>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="pic">
<input type="submit" value="Add" name='add'>
</form>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("Mydatabase",$con);
if(isset($_POST['add']))
{
/*File Upload start from here */
$input=$_FILES["pic"]["tmp_name"];
$directory="uploads/"; // folder name in which file will store
$file_name=$_FILES["pic"]["name"];
move_uploaded_file($input,$directory.$file_name);
$file=$directory.$file_name;
/*File Upload Ends here */
$qry="insert into Mytable(filename)value('$file')";
if(mysql_query($qry))
{
echo "Successful";
}
else
{
echo "Try Again";
}
}
?>
</body>
</html>
<html>
<title>File Upload</title>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="pic">
<input type="submit" value="Add" name='add'>
</form>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("Mydatabase",$con);
if(isset($_POST['add']))
{
/*File Upload start from here */
$input=$_FILES["pic"]["tmp_name"];
$directory="uploads/"; // folder name in which file will store
$file_name=$_FILES["pic"]["name"];
move_uploaded_file($input,$directory.$file_name);
$file=$directory.$file_name;
/*File Upload Ends here */
$qry="insert into Mytable(filename)value('$file')";
if(mysql_query($qry))
{
echo "Successful";
}
else
{
echo "Try Again";
}
}
?>
</body>
</html>
No comments:
Post a Comment