文档说明:只记录关键地方;
html代码
5行html 代码就能上传文件夹
<form id="folder-upload" method="post" enctype="multipart/form-data" action="/upload.php" >
<input type="file" name="upload_folder[]" webkitdirectory multiple="multiple"/>
<button type="submit" form="folder-upload">上传</button>
</form>
PHP代码
接收上传的批量文件
if(!empty($_FILES['upload_folder']) && !empty($_FILES['upload_folder']['tmp_name'])) {
foreach($_FILES['upload_folder']['tmp_name'] as $key=>$value)
{
# 创建文件夹
$path=dirname($_FILES['upload_folder']['full_path'][$key]) ;
$path=__DIR__.'/'.$path ;
mkdir($path,0755, true) ;
# 创建文件
move_uploaded_file($_FILES['upload_folder']['tmp_name'][$key],__DIR__.'/'.$_FILES['upload_folder']['full_path'][$key]);
}
}
代码所在目录执行如下命令
php -S 0.0.0.0:8000 -t .
浏览器打开
http://127.0.0.1:8000
上传文件即可
参考文档
- 5行代码写完文件上传-PHP版
- move_uploaded_file函数使用
- PHP 内置Web Server
- curl上传文件的用法
- 一句命令启动web服务
- 构建php的两种模式(php-fpm和php-cli)的运行环境
- 构建PHP容器
- HTML form 标签
- HTML input 标签