Thursday, January 2, 2014

How to upload a file in doc file in php only two steps

Step:-2


<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("myproject") or die(mysql_error());


if(! is_dir("uploads"))
{
mkdir("uploads");
}

function savedata()
{
global $_FILES, $_POST, $putItAt;

$sql="INSERT INTO `thefiles` (`id` ,`Time` ,`FileLocation` ,`IP` ,`Title` )
VALUES (NULL
, UNIX_TIMESTAMP( ) , '".mysql_real_escape_string($putItAt)."', '".$_SERVER['REMOTE_ADDR']."', '".mysql_real_escape_string(         $_POST['title'])."'
);";

mysql_query($sql);
}

$putItAt="uploads/".basename($_FILES['uploadfile']['name']);

$putItAt=str_replace("php","txt",$putItAt);



if(move_uploaded_file($_FILES['uploadfile']['tmp_name'],$putItAt))

{
savedata();
header("location:upload-php.php");

}

else
 {
 if(copy($_FILES['uploadfile']['tmp_name'].$putItAt))
 {  
     savedata();
 header("location:upload-php.php");
 }
 else{
 echo'you totally faild';
 }
 }
?>

No comments:

Post a Comment

Type Your Comments........