iarp Posted May 23, 2008 Share Posted May 23, 2008 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. Link to comment https://forums.phpfreaks.com/topic/106866-download-script-downloads-files-under-the-download-script-name/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.