Hello, wondering if anyone could help? I have created a file repository, the problem I am having is when a person other than the person who uploaded it tries to view a file which belongs to Microsoft Office i.e. Word, Excel etc... it opens the file and immediately a file conversion dialog box is displayed. The whole file is displayed with strange characters and I do not know why :s any ideas? The code I am using is:
$doc_no = $_GET['doc_no'];
$sql = "SELECT u.filetype, u.filesize, u.filename, u.user_id FROM uploads u, supervised sup WHERE sup.staff_id = '$current_user' AND sup.student_id = u.user_id AND u.doc_no = '$doc_no' AND u.saccess= 'yes'";
$result2 = $db->query($sql);
if (DB::isError($result2)){
$db->disconnect();
die ("error is with sql query" . $result2->getMessage());
}
while ($result2->fetchInto($row)){
$filetype = $row[0];
$filesize = $row[1];
$filename = $row[2];
$user_id = $row[3];
}
$rootDirectory = "upload/";
$userDirectory = $rootDirectory . "$user_id/";
$fileDirectory= $userDirectory . "$filename";
$file = fopen($fileDirectory, "r");
// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Content-Type: $filetype");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . $filesize);
header( "Content-Disposition: attachment; filename=\"$filename\"".";");
header("Content-Transfer-Encoding: binary\n");
readfile($fileDirectory);
print $file;