Why cannot I open the php file after it is downloaded? Solution

Source: Internet
Author: User
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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.