php - php - 克隆输入字段后获取文件数据
问题描述
我有输入文件的表格,可以通过特定按钮克隆。
当我选择一些文件,克隆输入字段,然后选择新文件(在新输入字段中)并提交时,我没有获得 ajax 文件中的所有第一个文件数据。
这是主页中的html:
<a href="#" class="clone-ele-btn" data-target="clone_box" data-des="clone_des">Clone</a>
<form action="#" method="post" enctype="multipart/form-data">
<span id="clone_box">
<input type='file' name='file[]' />
</span>
<span id="clone_des"></span>
<a href="#" class="new-files-btn">Submit</a>
</form>
查询:
// CLONE FILE INPUT FIELD
$(document).on("click", ".clone-ele-btn", function(e){
var target = $(this).data("target");
var des = $(this).data("des");
$( "#" + target ).clone().appendTo( "#" + des );
e.preventDefault();
});
// UPLOAD FILES
$(document).on("click", ".new-files-btn", function(e){
var form = $(this).closest('form')[0];
var formData = new FormData(form);
$.ajax ({
type: 'POST',
url: 'ajax/files-control.php',
data: formData,
dataType: 'json',
contentType: false,
cache: false,
processData:false
}).done(function(data)
{
....
...
..
文件-control.php:
<?PHP
var_dump ($_FILES);
?>
网络调试:
C:\wamp3\www\folder\ajax\files-control.php:13:
array (size=1)
'file' =>
array (size=5)
'name' =>
array (size=2)
0 => string 'IMG_8913.JPG' (length=12)
1 => string 'I-dont-have.jpg' (length=36)
'type' =>
array (size=2)
0 => string '' (length=0)
1 => string 'image/jpeg' (length=10)
'tmp_name' =>
array (size=2)
0 => string '' (length=0)
1 => string 'C:\wamp3\tmp\php36B6.tmp' (length=24)
'error' =>
array (size=2)
0 => int 1
1 => int 0
'size' =>
array (size=2)
0 => int 0
1 => int 50906
解决方案
未经测试,但尝试创建新的输入字段而不是克隆旧的。
let el = document.createElement('input');
el.type = 'file';
el.name = 'file[]';
document.getElementById('clone_box').appendChild(el);
jQuery 方式
$("#clone_box").append('<input type="file" name="file[]">');
更新
造成问题的不是字段,而是文件本身。它太大,超过了 php.ini上传限制。
UPLOAD_ERR_INI_SIZE
值:1;上传的文件超过了 php.ini 中的 upload_max_filesize 指令。
所以你需要调整你的 php.ini 设置或在 .htaccess 文件中重载它。
推荐阅读
- python - 获取所有外键字段
- c# - 尝试在 C# 中将强制转换运算符实现为可空类型时出错
- python - Selenium Web 驱动程序无法在 Google Chrome 网上商店中找到 div 类
- amazon-web-services - 我可以在一个 EC2 实例中挂载两个不同的文件夹吗?
- c++ - 如何索引转换后的用户数据值?
- php - 最小订单价值停止在 WooCommerce 中使用促销代码
- laravel - 当我在 vue js 中设置 axios 响应时,我在 laravel 刀片中得到一个空数组
- python - 行和列
- java - 在基于 TDD 的单元测试中处理 I/O
- javascript - ajax加载所有DOM元素后如何加载函数