html标记:
<input id="fileSelect" type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
Run Code Online (Sandbox Code Playgroud)
我用php上传多个文件.我想制作一组上传文件并使用ajax发送到服务器.如何制作多个选定文件的数组?
JavaScript的:
jQuery.ajax({
url: 'insertfiles.php',
type: "POST",
data: {
file: // array of selected files.
},
success: function(data){
},
error: function(data){
alert( 'Sorry.' );
}
});
Run Code Online (Sandbox Code Playgroud) jQuery.ajax
({
url: ajaxurl,
type: "POST",
xhr: function()
{
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener( 'progress', function( e )
{
if( e.lengthComputable )
{
// Append progress percentage.
var loaded = e.loaded;
var total = e.total;
var progressValue = Math.round( ( loaded / total ) * 100 );
// Bytes received.
jQuery( '.recievedValue' ).html( '' );
jQuery( '.recievedValue' ).append( formatFileSize( loaded ) + ' / ' );
// Total bytes.
jQuery( '.totalValue' ).html( '' );
jQuery( '.totalValue' ).append( formatFileSize( total …Run Code Online (Sandbox Code Playgroud) 我有一个带有值的数组: $array_metaValue
Array ( [0] => php [1] => ajax [2] => my [3] => profile [4] => java )
Run Code Online (Sandbox Code Playgroud)
第二个数组包含: $search_res[$e]
php
ajax
Run Code Online (Sandbox Code Playgroud)
但问题是计数值总是错误的。应该是2。
print_r( $array_metaValue);
for($e=0;$e<=count($search_res);$e++){
echo '<br>'.$search_res[$e].'<br>';
echo '<pre>';
$key = array_search($search_res[$e],$array_metaValue);
if(!$key==0)
{
$count=$count+1;
}
Run Code Online (Sandbox Code Playgroud)
$count 现在节省了 1。