gnawz Posted March 30, 2009 Share Posted March 30, 2009 Guys, I upload my files with the following scripts which work pretty well... <? unction addProdContent() { if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $sql = "SELECT * FROM mogas_productscontent WHERE Name = '$fileName'"; $result = dbQuery($sql); if (dbNumRows($result) == 1) { header('Location: index.php?view=add&error=' . urlencode('File already uploaded. Choose another one')); } else { $query = "INSERT INTO mogas_productscontent (Name, Size, Type, Content, DateAdded ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content', Now())"; mysql_query($query) or die('Error, query failed'); } } header('Location: index.php'); } ?> My problem is downloading the files. I mean for a user to click on a link and get a Save As Window. How do I achieve this? This is the script I am using currently... <? require_once 'mogas_utils.php'; //require_once'template.php'; //pgheader('MGS International - Downloads'); $query = "SELECT * FROM mogas_productscontent"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($productscontentid, $Name) = mysql_fetch_array($result)) { ?> <a href="d.php?id=<?php echo $productscontentid; ?>"><?php echo $Name; ?></a> <br> <?php } } ?> <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database $id = $_GET['id']; $query = "SELECT * FROM mogas_productscontent WHERE productscontentid = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($Name, $Type, $Size, $Content) = mysql_fetch_array($result); header("Content-length: $Size"); header("Content-type: $Type"); header("Content-Disposition: attachment; filename=$Name"); echo $Content; exit; } ?> What this does is attempt to open the PDF files in the same window with jumbled characters. I want to download my files thus: Give a user a link which they click to get a Save As dialogue Please help. Quote Link to comment https://forums.phpfreaks.com/topic/151734-small-problem-with-php-file-download/ Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Share Posted March 30, 2009 Shouldn't the very first line actually be <?php instead of <? may this be part the problem Quote Link to comment https://forums.phpfreaks.com/topic/151734-small-problem-with-php-file-download/#findComment-796845 Share on other sites More sharing options...
gnawz Posted March 30, 2009 Author Share Posted March 30, 2009 Hey, Thanks for your response... It does not affect a thing Quote Link to comment https://forums.phpfreaks.com/topic/151734-small-problem-with-php-file-download/#findComment-797149 Share on other sites More sharing options...
JeanieTallis Posted March 30, 2009 Share Posted March 30, 2009 By what I'm guessing, You click the pdf link, and it then opens up a dialog box with one button saying 'save as' ? I don't understand what it is you are trying to do what the 'user' clicks the link for download. Quote Link to comment https://forums.phpfreaks.com/topic/151734-small-problem-with-php-file-download/#findComment-797371 Share on other sites More sharing options...
gnawz Posted March 31, 2009 Author Share Posted March 31, 2009 I want when someone clicks., it opens a "Save As" That is what I want to achieve. Quote Link to comment https://forums.phpfreaks.com/topic/151734-small-problem-with-php-file-download/#findComment-797632 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.