jeff5656 Posted October 21, 2009 Share Posted October 21, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/178530-solved-when-i-upload-different-pdf-files-the-file-is-always-the-same/ Share on other sites More sharing options...
mikesta707 Posted October 21, 2009 Share Posted October 21, 2009 can I see the page that send $_GET['id'] Quote Link to comment https://forums.phpfreaks.com/topic/178530-solved-when-i-upload-different-pdf-files-the-file-is-always-the-same/#findComment-941545 Share on other sites More sharing options...
jeff5656 Posted October 21, 2009 Author Share Posted October 21, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/178530-solved-when-i-upload-different-pdf-files-the-file-is-always-the-same/#findComment-941548 Share on other sites More sharing options...
mikesta707 Posted October 21, 2009 Share Posted October 21, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178530-solved-when-i-upload-different-pdf-files-the-file-is-always-the-same/#findComment-941552 Share on other sites More sharing options...
jeff5656 Posted October 21, 2009 Author Share Posted October 21, 2009 Ok Now it works. I am really sorry I should have tested it more. It does seem to work. But at least I removed the quotes from $pid as you suggested :-) Quote Link to comment https://forums.phpfreaks.com/topic/178530-solved-when-i-upload-different-pdf-files-the-file-is-always-the-same/#findComment-941556 Share on other sites More sharing options...
mikesta707 Posted October 21, 2009 Share Posted October 21, 2009 haha it happens. You can mark the topic as solved by clicking the solved button at the bottom of the threads Quote Link to comment https://forums.phpfreaks.com/topic/178530-solved-when-i-upload-different-pdf-files-the-file-is-always-the-same/#findComment-941562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.