demo.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Project in PHP</title>
</head>
<body bgcolor=tan>
<h1><font color="firebrick">PHP MySQL </font></h1>
<form action="success.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="box" value="100000">
<table width="500" border="1">
<tr><td><b><label for='name'>Name :</b></label></td> <td><input type="text" name="Uname" size="20" /></td></tr>
<tr><td><b><label for='mail'>Email :</b></label></td><td><input type="text" name="mail" size="20" /></td></tr>
<tr><td><b> <label for='Updated_file'>Attachements:</b></label></td> <td> <input type="file" name="Updated_file" id="Updated_file" /></td></tr>
<tr><td colspan="2" align="center"><input type="Submit" value="Submit" name="Submit" id="Submit" onClick="return validate();"> <input type="reset" value="Reset" name="reset"> </td></tr>
</table>
</form>
</body>
</html>
success.php
<?php
$con = mysql_connect("localhost", "root");
mysql_select_db("connect_db", $con);
/*$sql = "CREATE TABLE upload1 (
id INT NOT NULL AUTO_INCREMENT,
User_Name VARCHAR(30) NOT NULL,
Email VARCHAR(30) NOT NULL,
name VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
size INT NOT NULL,
content MEDIUMBLOB NOT NULL,
PRIMARY KEY(id)
)";
mysql_query($sql,$con);*/
$Uname = $_POST['Uname'];
$mail = $_POST['mail'];
error_reporting(0);
$fileName = $fileName . basename ($_FILES['Updated_file']['name']);
$tmpName = move_uploaded_file($_FILES['Updated_file']['tmp_name'], $fileName);
$fileSize = $_FILES['Updated_file']['size'];
$fileType = $_FILES['Updated_file']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$query = "INSERT INTO upload1 (User_Name, Email, name, size, type, content) VALUES ('".$Uname."', '".$mail."', '".$fileName."', '".$fileSize."', '".$fileType."', '".$content."' )";
mysql_query($query) or die("Error, query failed");
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM upload1");
while($row = mysql_fetch_array($result))
{
echo "<font color='red'>Name :</font> ".$row['User_Name'].",<br />";
echo "<font color='blue'>Email :</font>".$row['Email'].",<br />";
echo "<font color='green'>Attachements :</font>"."<a href=$fileName > Open Attachments</a>".".<br />";
}
mysql_close($con);
?>
Here Insert is success. But My problem is unable to open the matching attachment. In my code Last updating file is open to all names.
Plz help me.