Page 1 of 1

Full name not shwing in file download

Posted: Sun Jul 22, 2007 5:47 am
by wasir
I am using this script for file download from database. It downloads fine but shows only the first word of the file name. eg if file name is 'my name.doc', it downloads as 'my.doc'. Please advice what am I doing wrong here...

Code: Select all

<?php
include ('functions.php5');
session_start();

if (isset($_SESSION['valid_user'])) {
	if (!$link = dbconn()) {
		echo getHeader();
		echo '<p>Error1: ' . mysqli_connect_error() . '</p>';
		echo getFooter();
		exit;
	}

	$qid    = $_GET['qid'];

	if (!$resultget = @mysqli_query($link, 'SELECT * FROM `tblupload` WHERE id = \'' . $qid . '\'')) {
		echo getHeader();
		echo '<p>Error: ' . mysqli_error($link) . '.</p>';
		echo getFooter();
		mysqli_close($link);
		exit;
	}
	while ($attachlst = mysqli_fetch_assoc($resultget)) {
		$name = $attachlst['name'];
		$type = $attachlst['type'];
		$size = $attachlst['size'];
		$content = $attachlst['content'];
	};

	header('Content-length:' . $size . '');
	header('Content-type:' . $type . '');
	header('Content-Disposition: attachment; filename=' . $name . '');

	echo $content;
	
}
echo getHeader();
echo '<p> You are not logged in.</p>';
echo '<p class=nav><a href="login.php5">Login</a></p>';
echo getFooter();
exit;
?>

Posted: Sun Jul 22, 2007 7:03 am
by feyd
Quotes are needed, I would suspect.

Posted: Sun Jul 22, 2007 7:08 am
by wasir
I tried using double quotes on the variable but it was downloading as actual variable eg. $name

Posted: Sun Jul 22, 2007 7:11 am
by s.dot
Did you try like this?

Code: Select all

header('Content-Disposition: attachment; filename="' . $name . '"');

Posted: Sun Jul 22, 2007 7:16 am
by wasir
no, I was trying different (of course wrong) way.

Thanks a lot your help. It works now.

:D