0

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

3
Contributors
2
Replies
15
Views
5 Years
Discussion Span
Last Post by TonyG_cyprus
0

Where did you moving your file ? If you want to download uploaded file first you have to move uploaded file to a folder in your hosting move_uploaded_file($_FILES['imagefile']['tmp_name'], "uploads/".$fileName) function will move your file to uploads/ directory.

After that you can download your file <a href='uploads/$fileName'>Download</a>

0

Also, watch your quotes, i.e

<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>

None of these are properly quoted.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.