The file cannot be opened after the PHP file is downloaded?
File Upload code:
$page _title= ' upload file ';
Include (' Include/header.inc ');
$counter = 3; Number files of allow upload.
if (Isset ($_post[' submitted ')) {//hidden form
Require_once ('/conn.php '); Connect to the database.
for ($i =0; $i < $counter; $i + +) {//process each uploaded file.
$filename = ' upload '. $i; //
$description = ' description '. $i;
Check for file.
if (Isset ($_files[$filename]) && ($_files[$filename [' ERROR ']!=4)) {
Check discription
if (!empty ($_post[$description])) {
$d =trim ($_post[$description]);
}else{
$d =null;
}
Add a record to the database
$query = "INSERT into uploads (file_name,file_size,file_type,description) VALUES (' {$_files[$filename [' name ']} ', ' {$_ files[$filename [' Size ']} ',
' {$_files[$filename] [' type ']} ', ' $d ') ';
$result = @mysql_query ($query);
if ($result) {
$upload _id=mysql_insert_id ();
Move uploaded files to a new location
if (Move_uploaded_file ($_files[$filename [' Tmp_name '], "uploads/$upload _id")) {
Echo ' has '. ($i + 1). ' File has been uploaded ';
}else{
Echo ' has '. ($i + 1). ' File upload failed ';
$query = "DELETE from uploads WHERE upload_id= $upload _id";
$result = @mysql_query ($query);
}
}else{//if query no OK.
Echo ' Submit an error please try again ';
}
}
}
}
?>
Include (' Include/footer.inc ');
?>
File download code:
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 ('./conn.php '); Connect to the database.
Get the information for this file.
$query = "Select file_name, File_type, file_size from uploads WHERE upload_id= $uid";
$result = mysql_query ($query);
List ($FN, $ft, $fs) = Mysql_fetch_array ($result);
$the _file = ' uploads/'. $uid;
}
Check if it exists.
if (file_exists ($the _file)) {
Send the file.
Header ("Content-type: $ft");
Header ("content-disposition:attachment; Filename=\ "$FN \" ");
Header ("Content-length: $fs");
ReadFile ($the _file);
} else {//File doesn ' t exist.
$page _title = ' File Download ';
Include ('./include/header.inc ');
Echo '
The file could not being located on the server. We apologize for any inconvenience.
';
Include ('./include/footer.inc ');
}
} else {//No valid upload ID.
$page _title = ' File Download ';
Include ('./include/header.inc ');