我有一个文件上传器(HTML / CSS / Jquery),我们可以调用它uploader_1
,另一个只调用(HTML,PHP),uploader_2
。我正在尝试通过uploader_1
将所有文件上传到表单的末尾。出于某种原因,在调整代码和所有内容之后,在我的验证php文件中,我可以获得$_FILES
来自uploader_2
的所有信息,但是,uploader_1
中没有任何内容,不在$_FILES
上,也不在$_POST
。
UPLOADER_1
HTML
<section class="col col-sm-5 rui" id="mupload5">
<label class="label" for="file5">
<b>Example</b>
<p>Description</p>
</label>
<div class="file-uploader__message-area">
<p>Select a file</p>
</div>
<div class="file-chooser">
<input type="file" class="file-chooser__input" id="file5">
</div>
<?php
listPdf($id, 5);
?>
</section>
Jquery的
//jQuery plugin
(function( $ ) {
$.fn.uploader = function( options ) {
var settings = $.extend({
MessageAreaText: "There is no file selected.",
MessageAreaTextWithFiles: "File list:",
DefaultErrorMessage: "Failed opening file.",
BadTypeErrorMessage: "Invalid type of file.",
acceptedFileTypes: ['pdf', 'jpg', 'gif', 'jpeg', 'bmp', 'tif', 'tiff', 'png', 'xps', 'doc', 'docx',
'fax', 'wmp', 'ico', 'txt', 'cs', 'rtf', 'xls', 'xlsx']
}, options );
var uploadId = 1;
//update the messaging
$('.file-uploader__message-area p').text(options.MessageAreaText || settings.MessageAreaText);
//create and add the file list and the hidden input list
var fileList = $('<ul class="file-list"></ul>');
var hiddenInputs = $('<div class="hidden-inputs hidden"></div>');
$('.file-uploader__message-area').after(fileList);
$('.file-list').after(hiddenInputs);
//when choosing a file, add the name to the list and copy the file input into the hidden inputs
$('.file-chooser__input').on('change', function(){
var file = $('.file-chooser__input').val();
var fileName = (file.match(/([^\\\/]+)$/)[0]);
//clear any error condition
$('.file-chooser').removeClass('error');
$('.error-message').remove();
//validate the file
var check = checkFile(fileName);
if(check === "valid") {
// move the 'real' one to hidden list
$('.hidden-inputs').append($('.file-chooser__input'));
//insert a clone after the hiddens (copy the event handlers too)
$('.file-chooser').append($('.file-chooser__input').clone({ withDataAndEvents: true}));
//add the name and a remove button to the file-list
$('.file-list').append('<li style="display: none;"><span class="file-list__name">' + fileName + '</span><button class="removal-button" data-uploadid="'+ uploadId +'"></button></li>');
$('.file-list').find("li:last").show(800);
//removal button handler
$('.removal-button').on('click', function(e){
e.preventDefault();
//remove the corresponding hidden input
$('.hidden-inputs input[data-uploadid="'+ $(this).data('uploadid') +'"]').remove();
//remove the name from file-list that corresponds to the button clicked
$(this).parent().hide("puff").delay(10).queue(function(){$(this).remove();});
//if the list is now empty, change the text back
if($('.file-list li').length === 0) {
$('.file-uploader__message-area').text(options.MessageAreaText || settings.MessageAreaText);
}
});
//so the event handler works on the new "real" one
$('.hidden-inputs .file-chooser__input').removeClass('file-chooser__input').attr('data-uploadId', uploadId);
//update the message area
$('.file-uploader__message-area').text(options.MessageAreaTextWithFiles || settings.MessageAreaTextWithFiles);
uploadId++;
} else {
//indicate that the file is not ok
$('.file-chooser').addClass("error");
var errorText = options.DefaultErrorMessage || settings.DefaultErrorMessage;
if(check === "badFileName") {
errorText = options.BadTypeErrorMessage || settings.BadTypeErrorMessage;
}
$('.file-chooser__input').after('<p class="error-message">'+ errorText +'</p>');
}
});
var checkFile = function(fileName) {
var accepted = "invalid",
acceptedFileTypes = this.acceptedFileTypes || settings.acceptedFileTypes,
regex;
for ( var i = 0; i < acceptedFileTypes.length; i++ ) {
regex = new RegExp("\\." + acceptedFileTypes[i] + "$", "i");
if ( regex.test(fileName) ) {
accepted = "valid";
break;
} else {
accepted = "badFileName";
}
}
return accepted;
};
};
}( jQuery ));
//init
$(document).ready(function(){
$('.fileUploader').uploader({
MessageAreaText: "Select a file."
});
});
UPLOADER_2
HTML
<section class="col col-sm-5 rui">
<label class="label" for="file6"><b>IPO e/ou Documentos Técnicos</b></label>
<div class="upload-control">
<input type="file" class="input-sm " name="file6" id="file6" style="height: 34px;" <?= $d; ?> />
<button type="button" class="btn btn-labeled btn-danger force-auto-width add" aria-label="Left Align" id="deleteipo" >
<span class="fa fa-trash" aria-hidden="true"></span>
</button>
<?php
listPdf($id, 6);
?>
</section>
现在我想要获取文件信息的是PHP,这是我提交的URL ..
PHP
print_r($_FILES);
echo 'HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEERE'.$_FILES['file5'];
die();
if ( $_FILES['file2']['size'] == 0 )
{
$errors[12] = "Insert file 2";
}else{
unset($errors[12]);
}
if ($_POST['waranty'] == 7 and $_FILES['file3']['size'] == 0)
{
$errors[13] = "Insert file 3";
}else{
unset($errors[13]);
}
if ( $_FILES['file1']['size']['0'] == 0)
{
$errors[14] = "Insert file 1";
}else{
unset($errors[14]);
}
在print_r
或echo
无论我放入Uploader_1,它都没有显示......发生了什么?我能做什么?一直试图以这么多方式得到它......
PRINT_R退货:
Array (
[file2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 )
[file3] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 )
[file1] => Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => )[tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) )
[file4] => Array ( [name] => Array ( [0] => ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 4 ) [size] => Array ( [0] => 0 ) )
[file6] => Array ( [name] => 17.png [type] => image/png [tmp_name] => /tmp/phpHJGS6F [error] => 0 [size] => 7014 ) ) HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEERE
答案 0 :(得分:0)
所以我得到了更新。我设法将文件导入$_FILES
。所以我现在可以使用新的上传(上传1)来做我需要做的事情。但我现在有一个新问题。我有6个部分需要上传文件,不同的文件。我可以有1 100%的工作,但是第二个会破坏一切。您可以在此代码笔上看到演示。
1个上传部分:http://codepen.io/heavenkinder/pen/BzzPrX
2个上传部分:http://codepen.io/heavenkinder/pen/XKKBBa
在输入1个文件后,无论在哪里,一切都停止工作或工作。我不知道为什么,我一直试图分离两个文件输入,但有相同的,让我们说模板。我应该分开javascript吗?为HTML中的输入指定不同的名称,并为每个输入使用javascript?