Jak wybrać wiele plików z?
Jak wybrać wiele plików za pomocą <input type="file">
?
9 answers
Nowa odpowiedź:
W HTML5 możesz dodać atrybut multiple
, Aby Wybrać więcej niż 1 plik.
<input type="file" name="filefield" multiple="multiple">
Stara odpowiedź:
Możesz wybrać tylko 1 plik na
<input type="file" />
. Jeśli chcesz wyślij wiele plików będziesz musiał użyć wielu znaczników wejściowych lub użyć Flash lub Silverlight.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-02 15:31:22
Istnieje również HTML5 <input type="file" multiple />
(Specyfikacja ).
Obsługa przeglądarki jest całkiem dobra na pulpicie (tylko nie obsługiwana przez IE 9 i wcześniejsze), mniej dobra na urządzeniach mobilnych, chyba dlatego, że trudniej jest poprawnie zaimplementować w zależności od platformy i wersji.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-19 13:27:38
Całość powinna wyglądać tak:
<form enctype='multipart/form-data' method='POST' action='submitFormTo.php'>
<input type='file' name='files[]' multiple />
<button type='submit'>Submit</button>
</form>
Upewnij się, że masz atrybut enctype='multipart/form-data'
w tagu <form>
, albo nie możesz odczytać plików po stronie serwera po przesłaniu!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-22 21:34:50
Ten plugin jQuery (Plik jQuery Upload Demo) robi to bez Flasha, w formie, której używa:
<input type='file' name='files[]' multiple />
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-13 00:50:42
Możesz to zrobić teraz z HTML5
W istocie używa się atrybutu multiple na wejściu pliku.
<input type='file' multiple>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-05 22:35:54
HTML5 dostarczył nowy atrybut multiple dla elementu wejściowego, którego atrybutem typu jest plik. Możesz więc wybrać wiele plików, a IE9 i poprzednie wersje tego nie obsługują.
Uwaga: ostrożnie z nazwą elementu wejściowego. jeśli chcesz przesłać wiele plików, powinieneś użyć array, a nie string jako wartości atrybut name.
Ex: input type= "file" name= " myphotos[]" multiple= "multiple"
A jeśli używasz php to dostaniesz dane w $_FILES i użyj var_dump ($_FILES) i zobacz wyjście i wykonanie przetwarzania Teraz możesz iterować i zrobić resztę
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-21 10:39:05
<form action="" method="post" enctype="multipart/form-data">
<input type="file" multiple name="img[]"/>
<input type="submit">
</form>
<?php
print_r($_FILES['img']['name']);
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-13 19:58:14
To proste ...
<input type='file' multiple>
$('#file').on('change',function(){
_readFileDataUrl(this,function(err,files){
if(err){return}
console.log(files)//contains base64 encoded string array holding the
image data
});
});
var _readFileDataUrl=function(input,callback){
var len=input.files.length,_files=[],res=[];
var readFile=function(filePos){
if(!filePos){
callback(false,res);
}else{
var reader=new FileReader();
reader.onload=function(e){
res.push(e.target.result);
readFile(_files.shift());
};
reader.readAsDataURL(filePos);
}
};
for(var x=0;x<len;x++){
_files.push(input.files[x]);
}
readFile(_files.shift());
};
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-30 14:32:15
Skopiuj i wklej to do swojego html:
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
To przychodzi do ciebie, przeze mnie, z tej strony: http://www.html5rocks.com/en/tutorials/file/dndfiles/
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-01-05 09:50:17