view stuff help!
Posted: Tue Dec 30, 2008 2:01 pm
Okay somehow viewing files are working.
Somehow firefox is being gay when downloading stuff. When i use internet explorer it downloads .doc formats.
It won't do 2007 (.docx) for some stupid reason. Plus it displays jpgs and txt formats.
http://www. hereandhome. org/html/view_files. php
I also don't know why whenever open a document, the download_file.php shows up on the download box.
I want all files to download? What am I doing wrong??
Here is the code for view, download, and the sql query.
download_files.php
Thanks in advance
Somehow firefox is being gay when downloading stuff. When i use internet explorer it downloads .doc formats.
It won't do 2007 (.docx) for some stupid reason. Plus it displays jpgs and txt formats.
http://www. hereandhome. org/html/view_files. php
I also don't know why whenever open a document, the download_file.php shows up on the download box.
I want all files to download? What am I doing wrong??
Here is the code for view, download, and the sql query.
Code: Select all
<?php
$page_title = 'View Files';
require_once ('../mysql_connect.php');
$first = TRUE;
$query ="SELECT upload_id, file_name, ROUND(file_size/1024) AS fs,
DATE_FORMAT(date_entered, '%M %e, %Y') AS d FROM resume ORDER BY date_entered DESC";
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
if($first){
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="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;
}
echo "<tr>
<td align=\"left\"><a href=\"download_file.php?uid={$row['upload_id']}\">{$row['file_name']}</a></td>
<td align=\"center\">{$row['fs']}kb</td>
<td align=\"left\">{$row['d']}</td>
</tr>\n";
}
if($first) {
echo '<div align="center">There are currently no files to be viewed.</div>';
} else{
echo '</table>';
}
mysql_close();
?>Code: Select all
<?php
if (isset($_GET['uid'])){
$uid = (int) $_GET['uid'];
} else {
$uid = 0;
}
if($uid > 0) {
require_once('../mysql_connect.php');
$query = "SELECT file_name, file_type, file_size FROM resume WHERE upload_id=$uid";
$result = mysql_query ($query);
list ($fn, $ft, $fs) = mysql_fetch_array ($result, MYSQL_NUM);
mysql_close();
$the_file = '../uploads/' . $uid;
if(file_exists($the_file)) {
header ("Content-Type: $ft\n");
header ("Content-disposition:
attachment; filename=\"$fn\"\n");
header ("Content-Length: $fs\n");
readfile($the_file);
} else {
$page_title = 'File Download';
echo '<p><font color="red">The file could not be located on the server. We apologize for any inconvenience.</font></p>';
}
} else {
$page_title = 'File Download';
echo '<p><font color= "red">Please select a valid file to download.</font></p>';
}
?>
Code: Select all
CREATE TABLE resume (
upload_id int(10) UNSIGNED NOT NULL
AUTO_INCREMENT,
file_name VARCHAR(1000) NOT NULL,
file_size INT(255) UNSIGNED NOT NULL,
file_type VARCHAR(30) NOT NULL,
date_entered TIMESTAMP,
PRIMARY KEY (upload_id),
KEY (file_name),
KEY (date_entered)
)