Jump to content

Recommended Posts

Hey,

 

download.php

<?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;
}

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

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

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

// Determine the file name on the server.
$the_file = './files/' . $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);
	exit();

} 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');
}

}
include ('./includes/header.php');
$first = TRUE; // Initialize the variable.

// Query the database.
$query = "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT(date_entered, '%M %e, %Y') AS d FROM " . DB_UPLOADS . " ORDER BY date_entered DESC";
$result = mysql_query ($query);

// Display all the URLs.
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
$bg = ($bg == '#eeeeee' ? '#ffffff' : '#eeeeee');
// If this is the first record, create the table header.
if ($first) {
	echo '<div style="text-align: center;"><small>To use the links below, right click the File Name, Copy link location.<br />When dowloading files, you must SAVE the file with it\'s proper name.</small></div>';
	echo '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
<tr>
	<td align="left" width="20%"><font size="+1">File Name</font></td>
	<td align="left" width="40%"><font size="+1">Description</font></td>
	<td align="center" width="20%"><font size="+1">File Size</font></td>
	<td align="left" width="20%"><font size="+1">Upload Date</font></td>
</tr>';

	$first = FALSE; // One record has been returned.

} // End of $first IF.

// Display each record.
echo "	<tr bgcolor=\"' . $bg . '\">
	<td align=\"left\"><a href=\"./download.php?uid={$row['upload_id']}\">{$row['file_name']}</a></td>
	<td align=\"left\">" . stripslashes($row['description']) . "</td>
	<td align=\"center\">{$row['fs']}kb</td>
	<td align=\"left\">{$row['d']}</td>
</tr>\n";

} // End of while loop.

// If no records were displayed...
if ($first) {
echo '<div align="center">There are currently no files to be viewed.</div>';
} else {
echo '</table>'; // Close the table.
}

include ('./includes/footer.php');
?>

 

But if i link to download.php?uid=1 and it links to test.pdf firefox recognizes it as a pdf BUT it's actual download name is download.php

 

I've tried changing

$the_file = './files/' . $uid; 

to

$the_file = './files/' . $fn;

 

But still no go.

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.