Jump to content

[SOLVED] i no this is a common question


jeppers

Recommended Posts

i am still a newbee and i have designed a form to download files. the only problem is that the header information in set in an else statement.  i am not sure how to change this and call upon the header information from the top of the page. could you help

 

<?php # Script 12.10 - download_file.php

// This pages handles file downloads through headers.

// Check for an upload_id.
if (isset($_GET['uid'])) {
$uid = (int) $_GET['uid'];
} else { // Big problem!
$uid = 0;
}

if ($uid > 0) { // Do not proceed!

require_once ('includes/mysql_connect.php'); // Connect to the database.

// Get the information for this file.
$query = "SELECT file_name, file_type, file_size FROM uploads WHERE upload_id=$uid";
$result = mysql_query ($query);
list ($fn, $ft, $fs) = mysql_fetch_array ($result, MYSQL_NUM);
mysql_close(); // Close the database connection.

// Determine the file name on the server.
$the_file = 'uploads/' . $uid;

// Check if it exists.
if (file_exists ($the_file)) {

	// Send the file.
	header ("Content-Type: $ft\n");
	header ("Content-disposition: attachment; filename=\"$fn\"\n");
	header ("Content-Length: $fs\n");
	readfile ($the_file);

} else { // File doesn't exist.
	$page_title = 'File Download';
	include ('includes/header.php');
	echo '<p><font color="red">The file could not be located on the server. We apologize for any inconvenience.</font></p>'; 
	include ('includes/footer.php');
}

} else { // No valid upload ID.
$page_title = 'File Download';
include ('includes/header.php');
echo '<p><font color="red">Please select a valid file to download.</font></p>'; 
include ('includes/footer.php');
}
?>

 

 

Link to comment
Share on other sites

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.