Jump to content

Problem Using PHP to pull document out of MySQL


dprichard

Recommended Posts

I am trying to pull documents into a page using php.  The documents are stored in a mysql database.  The page works when I link to it from within a page, but when I try to drop the link in and go directly to the page, it tells me the document cannot be found.  This page requires a login, and I have tried logging in first to see if it makes a difference.  It works in Safari and Firefox when I paste the link in, but not Internet Explorer.  I know this is a weird one and I am not sure whether or not to put this in the php forum or mysql, but I really appreciate any help any of you can give on this one. 

 

Here is my script.

 

<?php
include 'includes/permissions/universal.php';

if(isset($_GET['docid'])) 
{
include 'config.php';


// if id is set then get the file with the id from database

$id    = $_GET['docid'];
$query = "SELECT document_file, document_file_name, document_file_size, document_file_type, download_count FROM document WHERE docid = '$id'";

$doc_count = mysql_query("SELECT download_count FROM document WHERE docid = '$id'") or die(mysql_error());
$row_doc_count = mysql_fetch_array($doc_count);

$download_total = ($row_doc_count['download_count'] + 1);

mysql_query("UPDATE document SET download_count = '$download_total' WHERE docid = '$id'") or die(mysql_error());

$user = $row_user['emp_id'];

mysql_query("INSERT INTO document_tracker(document_tracker_docid, document_tracker_uid, document_tracker_date) VALUES('$id', '$user', CURDATE())") or die(mysql_error());

$result = mysql_query($query) or die('Error, query failed');
list($document_file, $document_file_name, $document_file_size, $document_file_type) =                                  mysql_fetch_array($result);

header("Content-length: $document_file_size");
header("Content-type: $document_file_type");
header("Content-Disposition: attachment; filename=$document_file_name");
echo $document_file;

exit;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.