gopi n
2008-08-07 04:02:08 UTC
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) {
$fileName = $_FILES['userfile']['name']; //The original name of the file on the client machine.
$tmpName = $_FILES['userfile']['tmp_name']; //The temporary filename of the file in which the uploaded file was stored on the server.
$fileSize = $_FILES['userfile']['size']; //The size, in bytes, of the uploaded file.
$fileType = $_FILES['userfile']['type'];//The mime type of the file, if the browser provided this information. An example would be "image/gif".
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content); //Quote string with slashes
fclose($fp);
if(!get_magic_quotes_gpc()) { //Gets the current configuration setting of magic quotes gpc
$fileName = addslashes($fileName);
}
//include("{$_SERVER['DOCUMENT_ROOT']}/phpmyadmin/dbconnect.php");
$find_duplication="SELECT name from tbl_upload where name='".$fileName."'";
$res_duplication=mysql_num_rows($find_duplication);
/* if($res_duplication) {
die(mysql_error());
}*/
if($res_duplication == 0) {
$query = "INSERT INTO tbl_upload (name, size, type, content ) VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
echo "Record added Successfullly";
}
else {
echo "Sorry record already exist";
}
echo "
File $fileName uploaded
";
}
mysql_close();