上传文件HTML的输入标签FILE类型中的名称后要加[],作用是在HTML中向PHP建立数组,比如名称为pictures,多文件引用名称则为pictures[],实例如下:
| 代码如下 | 复制代码 |
| //手册中实例。 | |
选择文件后点击上传
| 代码如下 | 复制代码 |
print_r($_FILES); | |
查看源文件:
| 代码如下 | 复制代码 |
| Array ( [pictures] => Array ( [name] => Array ( [0] => file1.txt [1] => file2.txt [2] => file3.txt ) [type] => Array ( [0] => application/octet-stream [1] => application/octet-stream [2] => application/octet-stream ) [tmp_name] => Array ( [0] => D:EasyPHPtmpphp47.tmp [1] => D:EasyPHPtmpphp48.tmp [2] => D:EasyPHPtmpphp49.tmp ) [error] => Array ( [0] => 0 [1] => 0 [2] => 0 ) [size] => Array ( [0] => 94289 [1] => 65536 [2] => 102400 ) ) ) | |
假设名为 /file1.txt??和 /file2.txt 的文件被提交,则 $_FILES['pictures']['name'][0] 的值将是 file1.txt,而 $_FILES['pictures']['name'][1] 的值将是 file2.txt。类似的,$_FILES['file2.txt']['size'][0] 将包含文件 file1.txt 的大小,
立即学习“PHP免费学习笔记(深入)”;
有了上面信息了我们要实现多文件上传就简单了
| 代码如下 | 复制代码 |
|
class upload { function __construct($name, $ext=array(), $rename=true) { private function initupload() { $this->chkupload(); private function chkupload() { if ($up_file['size'] / 1024 > $this->up_max) { $up_allw = false; if ($up_file['size'] / 1024 > $this->up_max) { $this->uploading(); private function uploading() { if (move_uploaded_file($up_file['tmp_name'], $file_name)) { public function getupload() { function __destruct() {} | |
在上面我们会看到一个for ($i = 0; $i
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号