ZendFramework - 如何使用 zend_http_client 上传多个文件?
如何使用->setFileUpload()上传多个文件?
例如我有这个:
<form method="post"
action="/file/csvupload"
target="myadmin_b20301"
enctype="multipart/form-data">
<input type="text" name="test" id="test" value="">
<input type="file" name="file[]" id="attachment" class="attachment">
<input type="file" name="file[]" id="attachment" class="attachment">
<input type="file" name="file[]" id="attachment" class="attachment">
<input type="submit" name="submit" id="submit" value="Update">
</form>
PHP:(主要上传后,它推送到管理面板,这是另一篇文章)。
....
if (!$upload->isValid()) // /file/csvupload
{
....
$client = new Zend_Http_Client(); // upload now to administrator another copy
$client->setUri($uri);
$client->setParameterPost(array('test'=>'test');
//how do i tell here to use those same file[] which are multiple?
$client->setFileUpload('/tmp/Backup.tar.gz', 'bufile');
$client->request( );
How to upload multiple files with ->setFileUpload()?
For example i have this:
<form method="post"
action="/file/csvupload"
target="myadmin_b20301"
enctype="multipart/form-data">
<input type="text" name="test" id="test" value="">
<input type="file" name="file[]" id="attachment" class="attachment">
<input type="file" name="file[]" id="attachment" class="attachment">
<input type="file" name="file[]" id="attachment" class="attachment">
<input type="submit" name="submit" id="submit" value="Update">
</form>
PHP: (after main upload, it push to admin panel which is another post).
....
if (!$upload->isValid()) // /file/csvupload
{
....
$client = new Zend_Http_Client(); // upload now to administrator another copy
$client->setUri($uri);
$client->setParameterPost(array('test'=>'test');
//how do i tell here to use those same file[] which are multiple?
$client->setFileUpload('/tmp/Backup.tar.gz', 'bufile');
$client->request( );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对上述解决方案的补充是将
->setOptions(array('multiple' => 'multiple'))
添加到表单文件元素。或者只是将属性 multiple="multiple" 添加到您的 HTML 表单输入标记中。Multiple 是一种 HTML5 属性,允许一次选择多个文件,而不是每个文件元素选择一个。
An addition to the solutions above is to add
->setOptions(array('multiple' => 'multiple'))
to your form file element. Or just the attribute multiple="multiple" to your HTML form input tag.Multiple is a HTML5 Attribute and allows multiple file selections at once instead of one for each file element.
您只需为要上传的每个文件调用一次
setFileUpload()
即可。每次调用都会将文件添加到将上传的文件数组中。如果您想将文件数组上传到同一文件元素,请将代码更改为:
在文件名上使用数组括号表示法,就像在 HTML 中一样。
这导致:
You can just call
setFileUpload()
once for each file that you want to upload. Each call adds the file to an array of files that will be uploaded.If you would like to upload an array of files to the same file element, change your code to this:
Use the array bracket notation on the filename just like you would in HTML.
This results in: