SyntaxError: Unexpected token {
複数のファイルをアップロードするときにあります。一方、ファイルを1つだけアップロードすると、機能します。
PHP
$uploaddir = 'uploads/';
$arr = array();
foreach ($_FILES["uploadfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$file = $uploaddir . basename($_FILES['uploadfile']['name'][$key]);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'][$key], $file)) {
$arr['title'] = $_FILES['uploadfile']['name'][$key];
$arr['url'] = $file;
$arr['size'] = $_FILES['uploadfile']['size'][$key];
}
echo json_encode($arr);
}
}
JQUERY
onComplete: function(file, response){
response = JSON.parse(response);
console.log('data = '+response.title);
console.log('data = '+response.url);
console.log('data = '+response.size);
}
NEW VAR DUMP PHP(@ hek2mglコード付き)
array(2) {
[0]=>
array(3) {
["title"]=> string(27) "facebook-icon-east-west.jpg"
["url"]=> string(35) "uploads/facebook-icon-east-west.jpg"
["size"]=> int(35227)
}
[1]=>
array(3) {
["title"]=> string(25) "facebook-graph-search.jpg"
["url"]=> string(33) "uploads/facebook-graph-search.jpg"
["size"]=> int(53122)
}
}