i thought i had this working right, but I guess not.
I am trying to create a small site for uploading files and downloading files, and I thought I had the whole downloading thing working, but I guess not.
There is a trick to once I upload them. Each file that is uploaded is entered into the database and given a specific file number. These files arent saved in the system as the name that they are uploaded with. They are saved as their file number name plus their extension. So if you uploaded a word document called test.doc, it would show up in the filesystem as something like 40.doc.
So if I download these files using ftp, they are fine. all the data is there, just like they were uploaded. but when i try downloading these using my script with all of the "header(...)" stuff in it, it just opens a blank document. I dont really understand why. Here is my code for downloading a document. maybe someone can see what I am doing wrong. I dont know where my mistake is.
<?php
require_once('../logon_script.php');
$upload_num = $_GET['fnum'];
$query = "SELECT DISTINCT file_name, file_size, file_type, file_extension FROM
upload WHERE file_number = '$upload_num'";
$result = @mysql_query($query);
$file_name = NULL;
$file_size = NULL;
$file_type = NULL;
$path = "/my/test/path/";
while ($row = mysql_fetch_array($result))
{
$file_name = $row['file_name'];
$file_size = $row['file_size'];
$file_type = $row['file_type'];
$file_extension = $row['file_extension'];
}
$tfname = $upload_num . $file_extension;
if (is_file($tfname))
{
header("Content-Type: $file_type");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Transfer-Encoding: Binary");
header("Content-Length: " . $file_size);
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$tfname");
readfile("$path");
}
else
{
echo "<p>The file $path" . "$tfname doesnt exist.</p>\n";
}
?>
as you can see, I just pass the file number that i need, then i get some information about that file. i concatenate the file_number with the file_extension to get the name of the file as it exists on the server (red hat), and then i try to send it. the filenames are right, they exist. when i try screwing with the file names, the is_file call returns false, like it should.
so if someone has any ideas on what I am doing wrong, I am all ears.
thanks ahead of time.