Jump to content

Recommended Posts

In line 25 of this code, it uses header outputs to send the chosen file as a download to the user.  I am curious how you would go about changing this code on line 25 so that when the said image is clicked on it is viewed in the browser and not sent as a download prompt.  When viewing a page of all the downloads, the filenames are linked so that when you click on them you are sent to this script with a variable.  the link is something to this affect www.mysite.com/folder/download_file.php?uid=10.  I understand how this code works, I would just like some help to change it from a download prompt to a view file in browser code.  Any thoughts?  Thank you.

 

<?php 
// 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 paddles_class 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 = './paddles_class/' . $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.html');
	echo '<p><font color="red">The file could not be located on the server. We apologize for any inconvenience.</font></p>'; 
	include ('./includes/footer.html');
}

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

Link to comment
https://forums.phpfreaks.com/topic/53395-changing-some-header-outputs/
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.