Jump to content

[SOLVED] When I upload different pdf files, the file is always the same


jeff5656

Recommended Posts

I have a form and processing script to upload a pdf and store it in a database with a a table called "pdf".  The uploading and retrieval works perfectly.  However, every time I upload a file, it is always the same one, even when I browse and choose  totally different file!

Here's the form processor.  If you want to see the actual form let me know:

$description = mysql_real_escape_string($_POST['description']);
$category = mysql_real_escape_string($_POST['category']);
$title = mysql_real_escape_string($_POST['whatsit']);
$ref = mysql_real_escape_string($_POST['ref']);

if ($errmsg == "") {
if ($_REQUEST[completed] == 1) {
        move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
        $instr = fopen("latest.img","rb");
        $image = mysql_real_escape_string(fread($instr,filesize("latest.img")));
        if (strlen($instr) < 1000000) {
                mysql_query ("insert into pdf (title, imgdata, category, description, ref) values ('$title','$image', '$category', '$description', '$ref')");

                $errmsg = "Done";
        } else {
                $errmsg = "Too large!";
        }
} else {
        $errmsg = "Form not completed";
}}
?>

 

Here's how I retrieve it:

$pid=$_GET['id'];
$gotten = @mysql_query("select * from pdf WHERE pid ='$pid' ");
$row = @mysql_fetch_assoc($gotten);
$bytes = $row[imgdata];
header("Content-type: application/pdf");
header('Content-disposition: attachment; filename="thing.pdf"');
print $bytes;

 

(I get there with

<a href="pdfget.php?id=<?php echo $row['pid'];?>"><?php echo $row['title'];?></a>

Sure:

<?php
session_start();
if(isset($_POST['category'])) {
$_SESSION['category'] = $_POST['category'];
$category = $_POST['category'];
} elseif (isset($_SESSION['category'])) {
$category = $_SESSION['category'];
} else {
$category = 'sepsis';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../styles/table_design.css" type="text/css" />

<title>Untitled Document</title>
</head>

<body>

<table width"100%" border="1" align="center">
  
<?php include ("../connectdb.php"); 
$query2 = "SELECT * FROM `category` order by category ";
$results2 = mysql_query ($query2) or die (mysql_error());
while ($row2 = mysql_fetch_assoc ($results2)) {
?><td ><form name="category" method="post" action="displayactive.php"> 
<input type="hidden" name ="category" value="<?php echo $row2['category'];?>"/>
<input style="font-size:11px" type="submit" value="<?php echo ucfirst($row2['category']);?>" />
</form>

    </td><?php
}
?>

</table>
<h2 align="center"><?php echo $category;?></h2>
<h3 align="right"><a href="upload.php">Upload PDF/Add Category</a></h3>
<?php
$query = "SELECT * FROM pdf WHERE category = '$category' ORDER BY title ";
$results = mysql_query ($query) or die (mysql_error());
?>
<table bgcolor="#CCCCFF" width = "95%" border = "1" cellpadding = "2"
cellspacing = "2" align = "left">
<tr>
    <th>Title</th>
    <th>Reference</th>
    <th>Description</th>
    </tr>
    <?php

while ($row = mysql_fetch_assoc ($results)) {
?>
<tr>
<td><a href="pdfget.php?id=<?php echo $row['pid'];?>"><?php echo $row['title'];?></a></td>
<td><?php echo $row['ref'];?></td>
<td><?php echo $row['description'];?></td>
</tr>
<?php
     }
     ?>
</table>
</body>
</html>

hmm interesting. Does your database have the values you expect it to have? try echoing $pid and see what it has in it. Also, if pid is an int column, you can remove the single quotes around $pid in the query. single quotes denote strings

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.