<?php
$fujian = $_FILES['fujian'];
$fileData = array();

foreach($fujian['name'] as $idx=>$data){
	if( $fujian['error'][$idx] == 0 ){
		$id = uniqid().$idx;
		
		$filename = iconv('GBk', 'UTF-8//IGNORE', $fujian['name'][$idx]);
		$filename = $fujian['name'][$idx];
		$houzhui = substr(strrchr($filename, '.'), 1);
		$newName = "./uploader/{$id}.{$houzhui}";
		
		$fileData[] = array(
			"_id" => $id,
			"name" => $filename,
			"file" => $newName
		);
		
		rename($fujian['tmp_name'][$idx],$newName);
	}
}

$cardid = r('cid');

foreach($fileData as $f){
	print_r($f);
	$res = $wekan->cards->update(array(
		'_id'=>$cardid
	),array(
		'$push' => array(
			'attachments'=>$f
		)
	));
	print_r($res);
}

$data = getcard($cardid);
$json = eventData('attachmentschange',$data[$cardid]);
?>
<script>
parent.emitEventByJSON(<?=$json?>);
</script>