我一直在尝试一切,而且它开始让我感到紧张。我还在尝试学习PHP中的绳索,所以请耐心等待。
我正在使用class.uploader.php将文件上传到我的服务器。它可以正常工作,但我希望只是在上传完成后返回上传的文件。这就是我被困住的地方。
这是我的代码;
<?php
include('assets/plugins/filer/php/class.uploader.php');
$uploader = new Uploader();
$data = $uploader->upload($_FILES['files'], array(
'limit' => 10, //Maximum Limit of files. {null, Number}
'maxSize' => 10, //Maximum Size of files {null, Number(in MB's)}
'extensions' => null, //Whitelist for file extension. {null, Array(ex: array('jpg', 'png'))}
'required' => false, //Minimum one file is required for upload {Boolean}
'uploadDir' => 'upload/', //Upload directory {String}
'title' => array('name'), //New file name {null, String, Array} *please read documentation in README.md
'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)}
'replace' => false, //Replace the file if it already exists {Boolean}
));
if($data['isComplete']){
$info = $data['data'];
echo '<pre>';
print_r($info);
echo '</pre>';
}
if($data['hasErrors']){
$errors = $data['errors'];
print_r($errors);
}
?>
上传完成后,这就是它返回的内容;
Array
(
[files] => Array
(
[0] => upload/ - TEST - #01.wav
[1] => upload/ - TEST - #02.wav
)
[metas] => Array
(
[0] => Array
(
[date] => Wed, 22 Feb 2017 14:03:42 +0100
[extension] => wav
[file] => upload/ - TEST - #01.wav
[name] => - TEST - #01.wav
[old_name] => - TEST - #01.wav
[replaced] =>
[size] => 1244204
[size2] => 1.19 MB
[type] => Array
(
[0] => audio
[1] => wav
)
)
[1] => Array
(
[date] => Wed, 22 Feb 2017 14:03:42 +0100
[extension] => wav
[file] => upload/ - TEST - #02.wav
[name] => - TEST - #02.wav
[old_name] => - TEST - #02.wav
[replaced] =>
[size] => 1677356
[size2] => 1.60 MB
[type] => Array
(
[0] => audio
[1] => wav
)
)
)
)
我想要归来的是这样的;
Upload complete.
The following files has been uploaded:
- TEST - #02.wav
- TEST - #02.wav
现在尝试了一段时间,但我无法理解。有人在乎帮忙吗?我已经尝试过“echo $ _FILES ['files']”,但这并没有成功。
答案 0 :(得分:1)
您必须使用for()
函数循环遍历...
Upload complete.
The following files has been uploaded:
<?php
for($i = 0; $i < count($data['data']['metas']); $i++)
{
echo "- ".$data['data']['metas'][$i]["name"]."<br />";
}
?>
。例如下面给出的例子:
role='menu'
希望这会有所帮助!