Full name not shwing in file download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Full name not shwing in file download

Post 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;
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Quotes are needed, I would suspect.
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Post by wasir »

I tried using double quotes on the variable but it was downloading as actual variable eg. $name
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Did you try like this?

Code: Select all

header('Content-Disposition: attachment; filename="' . $name . '"');
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
wasir
Forum Commoner
Posts: 49
Joined: Sun Jul 08, 2007 11:28 pm

Post by wasir »

no, I was trying different (of course wrong) way.

Thanks a lot your help. It works now.

:D
Post Reply