http://personals-index.com/index1552.html http://personals-index.com/index1553.html http://personals-index.com/index1554.html http://personals-index.com/index1555.html http://personals-index.com/index1556.html http://personals-index.com/index1557.html http://personals-index.com/index1558.html http://personals-index.com/index1559.html http://personals-index.com/index1560.html http://personals-index.com/index1561.html http://personals-index.com/index1562.html http://personals-index.com/index1563.html http://personals-index.com/index1564.html http://personals-index.com/index1565.html http://personals-index.com/index1566.html http://personals-index.com/index1567.html http://personals-index.com/index1568.html http://personals-index.com/index1569.html http://personals-index.com/index1570.html http://personals-index.com/index1571.html http://personals-index.com/index1572.html http://personals-index.com/index1573.html http://personals-index.com/index1574.html http://personals-index.com/index1575.html http://personals-index.com/index1576.html http://personals-index.com/index1577.html http://personals-index.com/index1578.html http://personals-index.com/index1579.html http://personals-index.com/index1580.html http://personals-index.com/index1581.html http://personals-index.com/index1582.html http://personals-index.com/index1583.html http://personals-index.com/index1584.html http://personals-index.com/index1585.html http://personals-index.com/index1586.html http://personals-index.com/index1587.html http://personals-index.com/index1588.html http://personals-index.com/index1589.html http://personals-index.com/index1590.html http://personals-index.com/index1591.html http://personals-index.com/index1592.html http://personals-index.com/index1593.html http://personals-index.com/index1594.html http://personals-index.com/index1595.html http://personals-index.com/index1596.html http://personals-index.com/index1597.html http://personals-index.com/index1598.html http://personals-index.com/index1599.html http://personals-index.com/index1500.html http://personals-index.com/index1501.html http://personals-index.com/index1502.html http://personals-index.com/index1503.html http://personals-index.com/index1504.html http://personals-index.com/index1505.html http://personals-index.com/index1506.html http://personals-index.com/index1507.html http://personals-index.com/index1508.html http://personals-index.com/index1509.html http://personals-index.com/index1510.html http://personals-index.com/index1511.html http://personals-index.com/index1512.html http://personals-index.com/index1513.html http://personals-index.com/index1514.html http://personals-index.com/index1515.html http://personals-index.com/index1516.html http://personals-index.com/index1517.html http://personals-index.com/index1518.html http://personals-index.com/index1518.html http://personals-index.com/index1518.html http://personals-index.com/index1521.html http://personals-index.com/index1522.html http://personals-index.com/index1523.html http://personals-index.com/index1524.html http://personals-index.com/index1525.html http://personals-index.com/index1526.html http://personals-index.com/index1527.html http://personals-index.com/index1528.html http://personals-index.com/index1529.html http://personals-index.com/index1530.html http://personals-index.com/index1531.html http://personals-index.com/index1532.html http://personals-index.com/index1533.html http://personals-index.com/index1534.html http://personals-index.com/index1535.html http://personals-index.com/index1536.html http://personals-index.com/index1537.html http://personals-index.com/index1538.html http://personals-index.com/index1539.html http://personals-index.com/index1540.html http://personals-index.com/index1541.html http://personals-index.com/index1542.html http://personals-index.com/index1543.html http://personals-index.com/index1544.html http://personals-index.com/index1545.html http://personals-index.com/index1546.html http://personals-index.com/index1547.html http://personals-index.com/index1548.html http://personals-index.com/index1549.html http://personals-index.com/index1552.html http://personals-index.com/index1551.html http://personals-index.com/index1550.html http://personals-index.com/index1652.html http://personals-index.com/index1653.html http://personals-index.com/index1654.html http://personals-index.com/index1655.html http://personals-index.com/index1656.html http://personals-index.com/index1657.html http://personals-index.com/index1658.html http://personals-index.com/index1659.html http://personals-index.com/index1660.html http://personals-index.com/index1661.html http://personals-index.com/index1662.html http://personals-index.com/index1663.html http://personals-index.com/index1664.html http://personals-index.com/index1665.html http://personals-index.com/index1666.html http://personals-index.com/index1667.html http://personals-index.com/index1668.html http://personals-index.com/index1669.html http://personals-index.com/index1670.html http://personals-index.com/index1671.html http://personals-index.com/index1672.html http://personals-index.com/index1673.html http://personals-index.com/index1674.html http://personals-index.com/index1675.html http://personals-index.com/index1676.html http://personals-index.com/index1677.html http://personals-index.com/index1678.html http://personals-index.com/index1679.html http://personals-index.com/index1680.html http://personals-index.com/index1681.html http://personals-index.com/index1682.html http://personals-index.com/index1683.html http://personals-index.com/index1684.html http://personals-index.com/index1685.html http://personals-index.com/index1686.html http://personals-index.com/index1687.html http://personals-index.com/index1688.html http://personals-index.com/index1689.html http://personals-index.com/index1690.html http://personals-index.com/index1691.html http://personals-index.com/index1692.html http://personals-index.com/index1693.html http://personals-index.com/index1694.html http://personals-index.com/index1695.html http://personals-index.com/index1696.html http://personals-index.com/index1697.html http://personals-index.com/index1698.html
AJAXでphp経由でJSONファイルをcsvで保存。
// Save Action $("#btn-save").click(function(e) { console.log("--- Save Button .. ---"); var ary_data = g_list_data; // 送るデータ形式はJSONでなければ、PHP側でエラーが出る. send_data = JSON.stringify(ary_data); console.log('send_data',send_data); // AJAX $.ajax({ url: "./php/receive_json_save.php", type: "POST", //必要ないがサーバ側との整合のために明示しておいた方がよい。 // contentType: "Content-Type: application/json; charset=UTF-8", // 必要ないがサーバ側との整合のために明示しておいた方がよい。 // dataType: 'json', //受信形式 data: send_data }).success(function(data, status, xhr) { console.log("--- << 通信成功!! >> ---"); console.log("success!!"); console.log("data =" + data); console.log("status =" + status); console.log("xhr =" + xhr); }).error(function(xhr, status, error) { // 通信失敗時の処理 console.log("--- << 通信失敗!! >> ---"); console.log("error !!"); console.log("status =" + status); console.log("error =" + error); }).complete(function(xhr, status) { // 通信完了時の処理 console.log("fin"); console.log("status =" + status); }); });
<?php /* Version 2 */ // TRUEの場合、デバッグを出力. $RESPONSE = TRUE; /******************************************/ // DEBUG用のサブ関数 /******************************************/ function print_response($str){ global $RESPONSE; if($RESPONSE){ print_r($str."\n"); }else{ // print_r("false"); } } /******************************************/ // JSONファイルの読み込み // * JSONファイルは連想配列に変換 /******************************************/ $json_str = file_get_contents("php://input"); # 第二引数がtrueの場合、連想配列になる $json_obj = json_decode($json_str, true); /******************************************/ // ファイルオープン // * ファイル名はYYYYMMDDHHMMSS.csv /******************************************/ date_default_timezone_set('Asia/Tokyo'); $SAVE_DIR = "./data/"; $file_name = $SAVE_DIR.date("Ymd_His").".csv"; print_response("\$file_name =".$file_name); // ファイルのオープン $fp = fopen($file_name, 'w'); /******************************************/ // 連想配列を整形し、csvに保存 /******************************************/ if($fp){ foreach($json_obj as $i => $arrays){ /* 方法 1 */ // $field = array($arrays["number"], $arrays["name"], $arrays["comment"]); // $STATE_CSV = fputcsv($fp, $field); /* 方法 2 */ // 連想配列のvalueをcsv形式に整形 // * 連想配列の値を取得する方法 array_keys($ary), array_values($ary) $field = @implode(",", @array_values($arrays)); $field = $i.",".$field."\n"; $STATE_CSV = fputs($fp, $field); // デバッグログ出力 print_response($field); } }else{ print_response("Error: fopen()\n"); } // ファイルクローズ $STATE_FCLOSE = fclose($fp); /******************************************/ // エラー処理 /******************************************/ if(!$STATE_FCLOSE){ print_response("Error: fclose($fp)\n"); } if(!$STATE_CSV){ print_response("Error: fputcsv()\n"); } ?>