Hi
This is my pdf file upload code
<html><head>
<title>Upload a .pdf to a database</title>
<h2>Please select your .pdf</h2>
<form enctype=multipart/form-data action=test.php method=post>
<input type=hidden name=MAX_FILE_SIZE value=1000000>
<input type=hidden name=completed value=1>
Please choose a .pdf to upload: <input type=file name=imagefile><br>
Please enter the title of that document: <input name=whatsit><br>
then: <input type="submit" name="Submit" value="Submit"
/></form>
<?php
include("Database.php");
$val =new DB;
$val -> connect();
if (isset($_POST['Submit']))
{
$fileName = $_FILES['imagefile']['name'];
$tmpName = $_FILES['imagefile']['tmp_name'];
$fileSize = $_FILES['imagefile']['size'];
$fileType = $_FILES['imagefile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$sql1 = "INSERT INTO `test` (`pdf`,`name` ,`size` ,`type`)VALUES ('".$content."','" .$fileName."','".$fileSize."','".$fileType.
"' )";
$res1 = mysql_query($sql1) ;
echo $fileName;
echo $fileSize;
echo $fileType;
}
?>
</body>
</html>
Download code-
<?php
include("Database.php");
$val =new DB;
$val -> connect();
$query = "SELECT name, type, size, pdf FROM test WHERE id = 1";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result);
$bytes = $row[pdf];
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
print $bytes;
?>
But i am getting empty file...
So please help me