Why cannot I open the php file after it is downloaded? File upload code: & lt ;? Php # upload a file & nbsp; $ page_title upload a file; & nbsp; include (includeheader. inc); & nbsp; $ counter3; Numberfilesofallowupload. & nbsp; if (isset ($ _ POST php file cannot be opened after it 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 the uploaded file to a new location
If (move_uploaded_file ($ _ FILES [$ filename] ['tmp _ name'], "uploads/$ upload_id ")){
Echo 'you'. ($ I + 1). 'file uploaded ';
} Else {
Echo 'you'. ($ 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 cocould not be 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 ');