So why not implement file download

Source: Internet
Author: User
$root = "d:/wamp/www/new Folder/";
if (Is_dir ($root))
{
$openHandle =opendir ($root);
while (false!== ($file =readdir ($openHandle)))
{
if (!is_dir ($root. $file))
{
echo "". $file. "
";
echo "$root $file
";
}
}
Closedir ($openHandle);
}
Else
{
echo "folder does not exist";
}
?>
Why this code does not implement the file download browser: Sogou browser IE have tried


Reply to discussion (solution)

Download with header headers

Download with header headers Can you give me a test program?

Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}

already?? Are you okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}
No, just put the php file down.

Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}

Error code: 27

File_put_contents (' Download/excel.csv ', $str);
Header ("Location:download/excel.csv"); Let the computer automatically pop up the download dialog box

File_put_contents (' Download/excel.csv ', $str);
Header ("Location:download/excel.csv"); Let the computer automatically pop up the download dialog box where and how to add

Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}

if ($do = = ' down ') This judgment is always unsuccessful after the code in the curly braces doesn't get a chance to do it.

Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}

Do you have a problem with this statement? "Echo". $root. $file. "
";" How to change it?

Href= '? Do change to href= ' A.php?do

A.php is your own. File name for PHP files


Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}

Error code: 27?? What's the description????? Out?? You take a look


Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}
No, just put the php file down.
What about me?? The way is not divided into documents, the type can be down, as long as the document has a limit to be able to be down, so you are listed in the file you want to be next to exclude PHP? type.

My file is called download.php, and I still can't.
$root = "D:/wamp/www/panjinli/downloadsouce";
if (Is_dir ($root))
{
$openHandle =opendir ($root);
while (false!== ($file =readdir ($openHandle)))
{
if (!is_dir ($root. $file))
{
echo "". $root. $file. "
";
}
}
Closedir ($openHandle);
}else
{
echo "folder does not exist";
}

$do = (isset ($_request[' do '))? Addslashes ($_request[' do '): ';
if ($do = = ' Down ')
{
$file = (isset ($_request[' file '))? Addslashes ($_request[' file '): ';
$path = (isset ($_request[' path '))? Addslashes ($_request[' path '): ';

Ob_start ();
function DownLoad ($info, $file)
{
Ob_clean ();
if (!file_exists ($info))
{
Exit (' Error: '. __line__ ', '. basename (__file__). '! ');
}
$info =file_get_contents ($info);

Header (' content-transfer-encoding:binary ');
Header (' Content-type:application/force-download; Name= '. $file. ');
Header (' content-disposition:attachment; Filename= '. $file. ');
Header (' cache-control:private ');
Header (' Pragma:no-cache ');
Header (' expires:0 ');
Echo $info;
Die ();
}
DownLoad ($path. $file, $file);
}
?>




Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}
No, just put the php file down.
What about me?? The way is not divided into documents, the type can be down, as long as the document has a limit to be able to be down, so you are listed in the file you want to be next to exclude PHP? type.



Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}
No, just put the php file down.
What about me?? The way is not divided into documents, the type can be down, as long as the document has a limit to be able to be down, so you are listed in the file you want to be next to exclude PHP? type.
Did you test it under Linux? The files that I put on windows that cannot be successfully executed on Linux downloads will be written to part of the messy content for support.




Has?? You, okay?

 
  ";   }   }   Closedir ($openHandle);} Else{echo "folder does not exist";} $do = (isset ($_request[' do '))? Addslashes ($_request[' do '): "; if ($do = = ' down ') {$file = (isset ($_request[' file"))? addslashes ($_request[' file ']): "; $path = (isset ($_request[' path"))? Addslashes ($_request[' path '): '; Ob_start (); function DownLoad ($info, $file) {Ob_clean (); if (!file_exists ($info)) { Exit (' Error: '. __line__ ', '. basename (__file__). '! ');} $info =file_get_contents ($info); header (' content-transfer-encoding:binary '); header (' content-type:application/ Force-download; Name= "'. $file. ' '); Header (' content-disposition:attachment; Filename= '. $file. '); Header (' cache-control:private '), header (' Pragma:no-cache '), header (' expires:0 '), echo $info;d ie ();} DownLoad ($path. $file, $file);}
No, just put the php file down.
What about me?? The way is not divided into documents, the type can be down, as long as the document has a limit to be able to be down, so you are listed in the file you want to be next to exclude PHP? type.
Did you test it under Linux? The files that I put on windows that cannot be successfully executed on Linux downloads will be written to a part of the messy content for support Ah, I???, everything is fine under Windows and Linux.
  • Related Article

    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.