header('Content-type: text/json; charset=UTF-8'); require_once "../include/global.include.php"; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $returnArr = array('code' => 200); if (!check_session()) { responseJSON('session expired', 440); } extract($_POST); if (!isset($media_id)) { responseJSON('invalid request'); } try { foreach ($media_id as $id) { $result = $wechat->dropMedia($id); if ($result['hasError']) { $returnArr = array('code' => 400, 'err' => $result['err']); break; } $query = 'UPDATE media_image SET deleted = 1 WHERE media_id = ?'; if (!$mysql->execute($query, array($id))) { throw new Exception($mysql->error); } } } catch (Exception $ex) { # log the exception log_error('media_image: drop', json_encode($media_id), $ex->getMessage()); $returnArr = array('code' => 500, 'err' => $ex->getMessage()); } responseJSON($returnArr); }
public function actionDelete() { $id = $_POST['id']; $sql = "delete from convey_answers where id=" . $id; iQuery($sql); responseJSON(['success' => true]); }
<?php $json = array(); $json['message'] = $message; $json['amazing_level'] = $json['message'] === null ? $productModel->product_mark : null; $json['commentList'] = null; if ($message === null) { foreach ($results as $key => $result) { $json['commentList'][$key]['id'] = $result['id']; $json['commentList'][$key]['text'] = $result['text']; $json['commentList'][$key]['create_time'] = $result['create_time']; $json['commentList'][$key]['amazing_level'] = $result['amazing_level']; } } $json = JSON($json); responseJSON($json);
<?php header('Content-type: application/json; charset=UTF-8'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { require_once "../include/global.include.php"; $returnArr = array('code' => 200); if (!check_session()) { $returnArr['code'] = 440; responseJSON('session expired', 440); } if (!isset($_FILES) || !isset($_GET['type'])) { die(json_encode(array('code' => 400, 'err' => 'Invalid request'))); } $type = $_GET['type']; $file = $_FILES['Filedata']; $imageData = getimagesize($file['tmp_name']); $extension = image_type_to_extension($imageData[2]); $available_type = array('image', 'thumb', 'voice', 'video'); try { if (!in_array($type, $available_type)) { die(json_encode(array('code' => 400, 'err' => 'Invalid media type'))); } // --------- save file in server ------------- // the orignal filename $filename = $file['name']; // copy the file according to media type $targetPath = "/upload/{$type}/"; $targetFileName = time() . $extension; $targetFile = dirname(__DIR__) . $targetPath . $targetFileName; if (!move_uploaded_file($file['tmp_name'], $targetFile)) { throw new Exception('file cannot be saved');