使用Javascript上载多个文件
有没有办法做到这一点?我的意思是将多个文件上载到文件夹 目前我有这个,但在这里我只能上传一个文件: 但我想做的是(如果你点击这个小+,然后进入新的输入,你可以选择另一个文件): 上传文件查看代码使用Javascript上载多个文件,javascript,php,cakephp,Javascript,Php,Cakephp,有没有办法做到这一点?我的意思是将多个文件上载到文件夹 目前我有这个,但在这里我只能上传一个文件: 但我想做的是(如果你点击这个小+,然后进入新的输入,你可以选择另一个文件): 上传文件查看代码 <div class="users view"> <h2><?php echo __('Lisa Fail'); ?></h2> <?php echo $this->Form->create('uploadFile', arr
<div class="users view">
<h2><?php echo __('Lisa Fail'); ?></h2>
<?php
echo $this->Form->create('uploadFile', array( 'type' => 'file'));
echo $this->Form->input('pdf_path', array('type' => 'file','label' => ''));
//echo $this->Form->input('files.', array('type' => 'file', 'multiple'));
echo $this->Form->end('Upload file');
$image_src = $this->webroot.'files/'.$image;
public function uploadFile() {
$filename = '';
if ($this->request->is('post')) { // checks for the post values
$uploadData = $this->data['uploadFile']['pdf_path'];
if ( $uploadData['size'] == 0 || $uploadData['error'] !== 0) { // checks for the errors and size of the uploaded file
return false;
}
$filename = basename($uploadData['name']); // gets the base name of the uploaded file
$uploadFolder = WWW_ROOT. 'files'; // path where the uploaded file has to be saved
$filename = time() .'_'. $filename; // adding time stamp for the uploaded image for uniqueness
$uploadPath = $uploadFolder . DS . $filename;
if( !file_exists($uploadFolder) ){
mkdir($uploadFolder); // creates folder if not found
}
if (!move_uploaded_file($uploadData['tmp_name'], $uploadPath)) {
return false;
}
}
$this->set('image',$filename);
}
我有一个Javascript,也许我可以使用它,或者不使用它(这是做什么的?:它做同样的事情,但它做数字输入,在这里你可以输入一个数字)
在视图文件中,我有这个,要使用这个js:
<table id="mytable">
<tr id="number0" style="display:none;">
<td><?php echo $this->Form->button(' - ',array('type'=>'button','title'=>'Click Here to remove this number')); ?></td>
<td><?php echo $this->Form->input('lisanumbrid', array ('name'=>'data[Kontaktid][lisanumbrid][0]')) ?></td>
</tr>
<tr id="trAdd"><td> <?php echo $this->Form->button('+',array('type'=>'button','title'=>'Click Here to add another number','onclick'=>'addNumber()')); ?> </td><td></td><td></td><td></td><td></td></tr>
</table>
<?php echo $this->Html->script('addNumber');
您只需添加新的输入字段,其名称包含[]
或[some\u array\u key]
:
$(文档).ready(函数(){
$(“.plus”)。单击(函数(){
$(“.files”).append(
);
});
});代码>
+
在控制器中,我需要这样做吗foreach($this->request->data['files']as$file){move_uplated_file($file['tmp_name']),WWW_ROOT.'uploads/'.$uuid..jpg');}
好的,这个脚本工作正常,我标记这个答案有用,但我不能接受答案,因为它什么都不做。我需要将这些文件上传到webroot/files,但它不起作用,如果我单击“提交”,它什么也不做。@frantsium当您提交表单时,所有输入字段都将被提交。我的答案是关于你的问题,但我想做的是(如果你点击这个小+,然后进入新的输入,在那里你可以选择另一个文件。)
是的,对不起,我的不好。我没有问如何将这些文件上传到webroot/files现在我有了这个javascript,缺少的只是:现在如何将这些文件上传到files文件夹?这个控制器不再工作了。
<table id="mytable">
<tr id="number0" style="display:none;">
<td><?php echo $this->Form->button(' - ',array('type'=>'button','title'=>'Click Here to remove this number')); ?></td>
<td><?php echo $this->Form->input('lisanumbrid', array ('name'=>'data[Kontaktid][lisanumbrid][0]')) ?></td>
</tr>
<tr id="trAdd"><td> <?php echo $this->Form->button('+',array('type'=>'button','title'=>'Click Here to add another number','onclick'=>'addNumber()')); ?> </td><td></td><td></td><td></td><td></td></tr>
</table>
<?php echo $this->Html->script('addNumber');