国产探花免费观看_亚洲丰满少妇自慰呻吟_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源碼下載

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐城市| 大冶市| 蕲春县| 中山市| 贵定县| 秦安县| 安西县| 通州区| 东辽县| 财经| 吴堡县| 诏安县| 阿坝县| 满城县| 承德市| 石台县| 北海市| 永仁县| 满洲里市| 神农架林区| 高唐县| 炎陵县| 石台县| 响水县| 宾川县| 将乐县| 湟中县| 武平县| 乌兰察布市| 桐梓县| 洛南县| 瓦房店市| 固原市| 大竹县| 正阳县| 河南省| 武隆县| 甘孜县| 孝昌县| 社旗县| 南丰县|