Jump to content

anthony-needs-you

Members
  • Posts

    52
  • Joined

  • Last visited

    Never

Everything posted by anthony-needs-you

  1. I have worked this out if(isset($_GET['id'])) { // get the article info from database $query = "SELECT id, title, content, name, path FROM courses WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; $pdfname = $row['name']; $pdfpath = $row['id']; } <a href="downloadpdf.php?id=<?=$pdfpath;?>"><?=$pdfname;?></a> The only thing I have now found is that when i open the pdf, it says its not supported file type or damaged or wasnt correctly decoded? If i open the file from the server it is fine but if i open it from the webpage it is not? Does anyone know why?
  2. Hi thanks for reading, I have put together a simple article cms script for a client. Via the backend they can type in their article and upload a pdf. The pdf needs to be displayed on the article page. So far I have worked out how to display a list of all the uploaded pdf's on the article page. They need the pdf associated with the article only displayed. I need some help :'( here is the article page: <?php include 'library/config.php'; include 'library/opendb.php'; // if no id is specified, list the available articles if(isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title FROM courses ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list $content2 = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title) = $row; $content2 .= "<li><a href=\"courseinfo.php?id=$id\">$title</a></li>\r\n"; } $content2 .= '</ol>'; $title = '<span class="course_grey">our<span class="orange_hed"> courses:</span>'; } if(isset($_GET['id'])) { // get the article info from database $query = "SELECT title, content FROM courses WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'library/closedb.php'; ?> <!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" /> <title>Train to Gain Thames Gateway Consortium :: NVQ Activity Leadership</title> <link href="../css/jebus.css" rel="stylesheet" type="text/css" /> <link href="../css/menu.css" rel="stylesheet" type="text/css" /> <link href="../css/text.css" rel="stylesheet" type="text/css" /> <link href="../css/links.css" rel="stylesheet" type="text/css" /> <script src="../bits/scripts/testimonials.js" type="text/javascript"> </script> </head> <body onload="rotateEvery(1)"> <div id="main_container"> <div id="main_header"> <!--..........................menu begins........................--> <div class="menucontainer"> <div class="submenu"> <a href="../news.html" class="submenu">News</a> <a href="../sitemap.html" class="submenu">Sitemap</a> <a href="../login.html" class="submenu">Partner Login</a> <a href="../casestudies.html" class="submenu">Case Studies</a> </div><!--submenu ends--> <div class="mainmenu"> <a href="../index.html" class="nav"><div class="menu_frames" id="home_frame" align="center">Home</div></a> <a href="../about.html" class="nav"><div class="menu_frames" id="about_frame" align="center">About Us</div></a> <a href="../courses/contact.html" class="nav"><div class="menu_frames" id="contact_frame" align="center">Contact Us</div></a> <a href="../employers.html" class="nav"><div class="menu_frames" id="employers_frame" align="center">Employers</div></a> <a href="../employees.html" class="nav"><div class="menu_end_frame" id="employees_frame" align="center">Employees</div></a> <div class="course_on" align="center">Course Guide</div> </div><!--mainmenu ends--> </div> <!--..........................menu ends........................--> <div class="logo_box" align="right"> <img src="../bits/images/general/logo_main.gif" height="58" width="106" border="0" class="logo_spacer" /><br /> <span class="logofont">Thames Gateway Consortium</span> </div> </div> <!--main_header ends--> <div id="flash_box"><img src="../bits/images/search/course.jpg" height="87" width="850" border="0" /></div> <!--flashbox--> <div id="content_box"> <div id="left_col"> <span class="quote_hed">What has <br /> Train to Gain <br /> done for you?</span><br /> <br /><br /> <span class="quote_body"> <div id="textrotator"><!--Quotations will be displayed here--></div> <br /> <br /> <br /> <a href="../contact.html#1" class="foot_link">have your say</a><img src="../bits/images/general/bubble_xs.png" height="17" width="23" border="0" /></span> </div> <!--...........................left_column ends................................--> <div id="right_col"> <div class="main_area"> <span class="course_grey">National Vocational Qualification</span><br /> <span class="course_or"><?php echo $title;?></span><br /><br /> <span class="body_grey"> <?php echo $content; // when displaying an article show a link // to see the article list if(isset($_GET['id'])) { ?></span> <p> </p> <span class="body_grey">__________________________________________________</span><br /><br /> <span class="grey_hed">NVQ</span><span class="orange_hed"> courses:</span> <span class="courselinks"><p><?php echo $content2; ?></p></span> <?php } ?> <span class="body_grey">(click on a course to find out more)</span> </div> <!--...........................main area ends...............................--> <div class="call_area"> <div class="call_pdf"> <span class="grey_hed">download</span><span class="orange_hed"> pdf</span><br /> <span class="grey_hed">of this course</span><br /><br /> <?php include 'config.php'; include 'opendb.php'; $query = "SELECT id, name FROM courses"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "id :{$row['id']} <br>" . "name : {$row['name']} <br>" ; } include 'closedb.php'; ?> <?php include 'library/config.php'; include 'library/opendb.php'; $query = "SELECT id, name FROM courses"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?> <a href="downloadpdf.php?id=<?=$id;?>"><?=$name;?></a> <br> <?php } } include 'library/closedb.php'; ?> </div> <div class="call_info"> <span class="orange_hed"> enquire</span><span class="grey_hed"> about<br /> this course</span><br /><br /> <a href="../contact.html" class="or"> click here</a></div> <div class="call"> <a href="../courseguide.html"><img src="../bits/images/general/search1.jpg" alt="click here to search our course guide" width="170" height="234" border="0" class="call_spa" /></a></div> <div class="contact_call_big"> <div class="contact_spa"> <span class="foot_link">Get a skills analysis or details of funded courses by calling us during office hours</span><br /> <br /> <span class="med_white"></span><br /> </div> </div> </div> <!--call area ends--> </div> <!--...........................right_column ends................................--> <!--...........................right_column ends................................--> <div class="clearboth" id="foo"><!--empty--></div> </div><!--content_box--> <div class="footer"> <div class="copyrightblock"> <span class="copyright">© Copyright Train to Gain 2008</span></div> <div class="footerblock"> <a href="../news.html" class="foot_link">News</a> <a href="../sitemap.html" class="foot_link">Sitemap</a> <a href="../login.html" class="foot_link">Partner Login</a></div> <div class="contactblock"> <span class="foot_link"><strong>Contact Us:</strong></span> <span class="foot_link"></span> </div> </div><!--footer--> <div class="clearboth" id="foo"></div> </div><!--main_container--> </body> </html> and here is the download page part: <?php error_reporting(E_ALL); if(isset($_GET['id'])) { include 'library/config.php'; include 'library/opendb.php'; $id = $_GET['id']; $query = "SELECT name, type, size, path FROM courses WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $filePath) = mysql_fetch_array($result); header("Content-Disposition: attachment; filename=$name"); header("Content-length: $size"); header("Content-type: $type"); readfile($filePath); include 'library/closedb.php'; exit; } ?> <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php include 'library/config.php'; include 'library/opendb.php'; $query = "SELECT id, name FROM courses"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?> <a href="downloadpdf.php?id=<?=$id;?>"><?=$name;?></a> <br> <?php } } include 'library/closedb.php'; ?> </body> </html> If you can help me you would make a sad guy very happy Thanks very much
×
×
  • 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.