{"action":"created","issue":{"url":"https://api.github.com/repos/kartik-v/bootstrap-fileinput/issues/109","labels_url":"https://api.github.com/repos/kartik-v/bootstrap-fileinput/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/kartik-v/bootstrap-fileinput/issues/109/comments","events_url":"https://api.github.com/repos/kartik-v/bootstrap-fileinput/issues/109/events","html_url":"https://github.com/kartik-v/bootstrap-fileinput/issues/109","id":53480535,"number":109,"title":"Please show me how to write a valid json response from my php upload script","user":{"login":"giangvy1011","id":9975901,"avatar_url":"https://avatars.githubusercontent.com/u/9975901?v=3","gravatar_id":"","url":"https://api.github.com/users/giangvy1011","html_url":"https://github.com/giangvy1011","followers_url":"https://api.github.com/users/giangvy1011/followers","following_url":"https://api.github.com/users/giangvy1011/following{/other_user}","gists_url":"https://api.github.com/users/giangvy1011/gists{/gist_id}","starred_url":"https://api.github.com/users/giangvy1011/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giangvy1011/subscriptions","organizations_url":"https://api.github.com/users/giangvy1011/orgs","repos_url":"https://api.github.com/users/giangvy1011/repos","events_url":"https://api.github.com/users/giangvy1011/events{/privacy}","received_events_url":"https://api.github.com/users/giangvy1011/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-06T04:44:20Z","updated_at":"2015-01-07T19:24:20Z","closed_at":null,"body":"HI,\r\n\r\nI am just a new php learner and i would like to integrate this plugins to my existing form. I have written my php script which processes file upload and set it up in urlUpload. However, when i click upload button, it returns invalid jason response. I don't know how to write a valid json response in my php code because this is out of my scope at this monent. Please help me by telling how to write a simple empty object in json response to make it work?\r\n\r\nHere is my php code:\r\n\r\n    if(isset($_POST[\"submit\"])){\r\n    require(\"../configs/dbconnect.php\");\r\n    /*Form variable   */\r\n    $owner = mysql_real_escape_string($_POST[\"owner\"]);\r\n    $title = mysql_real_escape_string($_POST[\"title\"]);\r\n    $description = mysql_real_escape_string($_POST[\"description\"]);\r\n    $city = mysql_real_escape_string($_POST[\"city\"]);\r\n    $brand = mysql_real_escape_string($_POST[\"brand\"]);\r\n    $marketprice = mysql_real_escape_string($_POST[\"marketprice\"]);\r\n    $price = mysql_real_escape_string($_POST[\"price\"]);\r\n    $phone = mysql_real_escape_string($_POST[\"phone\"]);\r\n    /*** the upload directory ***/\r\n    $upload_dir= 'uploads';\r\n\r\n    /*** numver of files to upload ***/\r\n    $num_uploads = 5;\r\n\r\n    /*** maximum filesize allowed in bytes ***/\r\n    $max_file_size  = 5000000;\r\n \r\n    /*** the maximum filesize from php.ini ***/\r\n    $ini_max = str_replace('M', '', ini_get('upload_max_filesize'));\r\n    $upload_max = $ini_max * 1024;\r\n\r\n    /*** a message for users ***/\r\n    $msg = 'Please select files for uploading';\r\n\r\n    /*** an array to hold messages ***/\r\n    $messages = array();\r\n\t$err=array();\r\n\r\n    /*** check if a file has been submitted ***/\r\n    if(isset($_FILES['file']['tmp_name']))\r\n    {\r\n        /** loop through the array of files ***/\r\n        for($i=0; $i < count($_FILES['file']['tmp_name']);$i++)\r\n        {\r\n            // check if there is a file in the array\r\n            if(!is_uploaded_file($_FILES['file']['tmp_name'][$i]))\r\n            {\r\n                $messages[] = 'No file uploaded';\r\n            }\r\n            /*** check if the file is less then the max php.ini size ***/\r\n            //elseif($_FILES['image']['size'][$i] > $upload_max)\r\n            //{\r\n            //    $messages[] = \"File size exceeds $upload_max php.ini limit\";\r\n            //}\r\n            // check the file is less than the maximum file size\r\n            elseif($_FILES['file']['size'][$i] > $max_file_size)\r\n            {\r\n                $messages[] = \"File size exceeds $max_file_size limit\";\r\n            }\r\n            else\r\n            {\r\n\t\t\t\t//$temp = explode(\".\", $_FILES[\"file\"][\"name\"][$i]);\r\n\t\t\t\t//$extension = end($temp);\r\n\t\t\t\t//$name[$i] = sha1(microtime()) . \".\" . $extension;\r\n\t\t\t\t$name[$i]=$_FILES[\"file\"][\"name\"][$i];\r\n                // copy the file to the specified dir \r\n                if(move_uploaded_file($_FILES['file']['tmp_name'][$i],$upload_dir.'/'.$name[$i]))\r\n                {\r\n                    /*** give praise and thanks to the php gods ***/\r\n                    $messages[] = $name[$i].' uploaded';\r\n\t\t\t\t\t$image_path[$i]=$upload_dir.'/'.$name[$i];\r\n                }\r\n                else\r\n                {\r\n                    /*** an error message ***/\r\n                    $messages[] = 'Uploading '.$name[$i].' Failed';\r\n                }\r\n            }\r\n        }\r\n    }\r\n\t$image_path_string=serialize($image_path);\r\n\t$sql = \"INSERT INTO memberpost(owner, title, description, city, brand, marketprice, price, phone, image) VALUES ('$owner', '$title','$description','$city','$brand','$marketprice','$price','$phone', '\" . $image_path_string . \"')\";\r\n\t$result = mysql_query($sql) or die (\"Could not insert data into DB: \" . mysql_error());\r\n\t if(sizeof($messages) != 0)\r\n    {\r\n        foreach($messages as $err)\r\n        {\r\n            echo $err.'<br />';\r\n        }\r\n    }\r\n    }\r\n\r\n\r\nMany thanks"},"comment":{"url":"https://api.github.com/repos/kartik-v/bootstrap-fileinput/issues/comments/69076149","html_url":"https://github.com/kartik-v/bootstrap-fileinput/issues/109#issuecomment-69076149","issue_url":"https://api.github.com/repos/kartik-v/bootstrap-fileinput/issues/109","id":69076149,"user":{"login":"Blackman21","id":496775,"avatar_url":"https://avatars.githubusercontent.com/u/496775?v=3","gravatar_id":"","url":"https://api.github.com/users/Blackman21","html_url":"https://github.com/Blackman21","followers_url":"https://api.github.com/users/Blackman21/followers","following_url":"https://api.github.com/users/Blackman21/following{/other_user}","gists_url":"https://api.github.com/users/Blackman21/gists{/gist_id}","starred_url":"https://api.github.com/users/Blackman21/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Blackman21/subscriptions","organizations_url":"https://api.github.com/users/Blackman21/orgs","repos_url":"https://api.github.com/users/Blackman21/repos","events_url":"https://api.github.com/users/Blackman21/events{/privacy}","received_events_url":"https://api.github.com/users/Blackman21/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T19:24:20Z","updated_at":"2015-01-07T19:24:20Z","body":"Hi,\r\n\r\nTry this http://php.net/manual/en/function.json-encode.php article.\r\n\r\nBr."}}