Jump to content

Recommended Posts

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.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/151734-small-problem-with-php-file-download/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.