douwen3973 2015-03-06 16:57
浏览 80

动态上传表单只上传一个文件

A form with one upload link already defined

<form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
Files to upload 
 <input name="file[]" type="file" multiple/><br>
    <button class="add_more">Add More Files</button>
    <input type="submit" value="Upload File" id="upload"/>
</form>

and I can add more links for more files if i wish

$(document).ready(function(){
    $('.add_more').click(function(e){
        e.preventDefault();
        $(this).before("<input name='file[]' type='file'/ multiple><br>");
    });
});

but after adding more links and files , when i process the form $_FILES array only contains the first file , from the link defined originally in the html.

the var_dump($_FILES) output is after uploading the file is

array(1) { ["file"]=> array(5) { ["name"]=> array(1) { [0]=> string(14) "xxxxxCV.doc" } ["type"]=> array(1) { [0]=> string(18) "application/msword" } ["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phph4u15e" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(63488) } } }

Is there a way to dynamically add file uploads that end up in $_FILES ?

If i put multiple file upload lines in the html and dont use the jquery adding a link, $_FILES contains multiple files .

max_file_uploads = 20 (php.ini)

there are (to me at least) good reasons why I need to store the files in the database rather than as a link

if i create a form with 2,3,4 etc links
ie

<input name="file[]" type="file" multiple/><br>
<input name="file[]" type="file" multiple/><br>
<input name="file[]" type="file" multiple/><br>
    <button class="add_more">Add More Files</button>
    <input type="submit" value="Upload File" id="upload"/>
</form>

i can upload the files and they are in $_FILES. If i start with one link and add more with jquery, only the file uploaded from the original HTML ( not those add with jquery) is in $_FILES

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)