Copy codeThe Code is as follows:
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> index_uploads </title>
</Head>
<Body>
<Form action = "uploads. php" method = "post" enctype = "multipart/form-data">
<Input type = "file" name = "file []">
<Br>
<Input type = "file" name = "file []">
<Br>
<Input type = "file" name = "file []">
<Br>
<Input type = "file" name = "file []">
<Br>
<Input type = "file" name = "file []">
<Br>
<Input type = "submit" value = "uploads">
</Form>
</Body>
</Html>
Index_uploads.php
Copy codeThe Code is as follows:
<? Php
Echo "<pre> ";
Print_r ($ _ FILES );
Echo "</pre> ";
$ Count = count ($ _ FILES ['file'] ['name']);
For ($ I = 0; $ I <$ count; $ I ++ ){
$ Tmpfile = $ _ FILES ['file'] ['tmp _ name'] [$ I];
$ Filefix = array_pop (explode (".", $ _ FILES ['file'] ['name'] [$ I]);
$ Dstfile = "uploads/files/". time (). "_". mt_rand (). ".". $ filefix;
If (move_uploaded_file ($ tmpfile, $ dstfile )){
Echo "<script> alert ('succeed! '); Window. location. href = 'listdir. php'; </script> ";
} Else {
Echo "<script> alert ('fail! '); Window. location. href = 'index _ uploads. php'; </script> ";
}
}
Uploads. php
Copy codeThe Code is as follows:
<? Php
Header ("content-type: text/html; charset = UTF-8 ");
$ Dirname = "uploads/files ";
Function listdir ($ dirname ){
$ Ds = opendir ($ dirname );
While ($ file = readdir ($ ds )){
$ Path = $ dirname. '/'. $ file;
If ($ file! = '.' & $ File! = '..'){
If (is_dir ($ path )){
Listdir ($ path );
} Else {
Echo "<tr> ";
Echo "<td> </td> ";
Echo "<td> <a href = 'download. php? Imgfile = $ file '> Download </a> </td> ";
Echo "</tr> ";
}
}
}
}
Echo "Echo "<table width = '700px 'border = '1px '> ";
Listdir ($ dirname );
Echo "</table> ";
Listdir. php
Copy codeThe Code is as follows:
<? Php
$ Imgfile = $ _ GET ['imgfile'];
$ Path = './uploads/files/'. $ imgfile;
$ Imgsize = filesize ($ path );
Header ("content-type: application/octet-stream ");
Header ("content-disposition: attachment; filename = {$ imgfile }");
Header ("content-length: {$ imgsize }");
Readfile ($ path );
Download. php
Download. php
Core download:
Copy codeThe Code is as follows:
Header ("content-type: application/octet-stream ");
Header ("content-disposition: attachment; filename = {$ imgfile }");
Header ("content-length: {$ imgsize }");
Readfile ($ path );