Return 个文件名来自 class.uploader.php
Return filenames from class.uploader.php
我一直在尝试一切,它开始让我感到不安。我仍在努力学习 PHP 中的诀窍,所以请多多包涵。
我正在使用 class.uploader.php 将文件上传到我的服务器。它可以正常工作,但我想 just return 上传完成后上传的文件。这就是我卡住的地方。
这是我的代码;
<?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);
}
?>
上传完成后,这是 returns;
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
)
)
)
)
我想要的return是这样的;
Upload complete.
The following files has been uploaded:
- TEST - #02.wav
- TEST - #02.wav
现在已经尝试了一段时间,但我无法弄清楚。有人愿意帮忙吗?我试过 "echo $_FILES['files']",但没有成功。
您必须使用 for()
函数循环遍历 $data['data']['metas']
。就像下面给出的例子:
...
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 />";
}
?>
希望对您有所帮助!
我一直在尝试一切,它开始让我感到不安。我仍在努力学习 PHP 中的诀窍,所以请多多包涵。
我正在使用 class.uploader.php 将文件上传到我的服务器。它可以正常工作,但我想 just return 上传完成后上传的文件。这就是我卡住的地方。
这是我的代码;
<?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);
}
?>
上传完成后,这是 returns;
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
)
)
)
)
我想要的return是这样的;
Upload complete.
The following files has been uploaded:
- TEST - #02.wav
- TEST - #02.wav
现在已经尝试了一段时间,但我无法弄清楚。有人愿意帮忙吗?我试过 "echo $_FILES['files']",但没有成功。
您必须使用 for()
函数循环遍历 $data['data']['metas']
。就像下面给出的例子:
...
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 />";
}
?>
希望对您有所帮助!