This article mainly introduces php multi-file upload and download examples. For more information, see
The code is as follows:
Index_uploads
Index_uploads.php
The code is as follows:
Echo"
";
print_r($_FILES);
echo "
";
$ 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
The code is as follows:
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"";
Echo"";
Echo"Download";
Echo"";
}
}
}
}
Echo "image download | image upload ";
Echo"
";Listdir ($ dirname );Echo"
";
Listdir. php
The code is as follows:
$ 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:
The code is as follows:
Header ("content-type: application/octet-stream ");
Header ("content-disposition: attachment; filename = {$ imgfile }");
Header ("content-length: {$ imgsize }");
Readfile ($ path );