国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

php多文件上傳和下載實現方法

2024-04-25 20:31:02
字體:
來源:轉載
供稿:網友

 文章介紹了用php實現多文件上傳和下載的實現方法,希望可以幫助到有所需求的朋友!

核心思路:

header("content-type:application/octet-stream");

header("content-disposition:attachment;filename={$imgfile}");

header("content-length:{$imgsize}");

readfile($path);

index_uploads.php文件代碼:

<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>

uploads.php文件代碼:

<?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>";

}

}

listdir.php文件代碼:

<?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><img src='$path'></td>";

echo "<td><a href='download.php?imgfile=$file'>Download</a></td>";

echo "</tr>";

}

}

}

}

echo "<h2>圖片下載|<a href='index_uploads.php'>圖片上傳</a></h2>";

echo "<table width='700px' border='1px'>";

listdir($dirname);

echo "</table>";

download.php文件代碼:

<?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);

常用php源碼下載

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁安市| 恩施市| 丰原市| 仙游县| 延长县| 思茅市| 永丰县| 长阳| 金坛市| 南岸区| 长岛县| 崇州市| 德阳市| 四川省| 句容市| 敦化市| 新巴尔虎右旗| 鲁甸县| 阜南县| 怀宁县| 连山| 阳曲县| 丰宁| 临猗县| 马龙县| 鸡泽县| 昭通市| 同心县| 张家港市| 开化县| 蕉岭县| 乳山市| 胶南市| 新宁县| 额尔古纳市| 灵寿县| 游戏| 壶关县| 大同市| 泰州市| 汉源县|