<?php 
include "bank.php";
$result = $conn->query("SELECT * FROM `users` WHERE token = '".$_GET['token']."' ");
//echo "SELECT * FROM `users` WHERE token = '".$_GET['token']."' ";

		 if ($result->num_rows > 0) {
				// output data of each row
				$row = $result->fetch_assoc(); 
				$id = $row['id'];
				$file_type_full = explode('.',$_FILES['myfile']['name']);
					$file_type = $file_type_full[1];
					if(ISSET($_FILES)){  
						$sound_path = "upload/";
						
					//	print_r($_FILES);
						
							if($file_type == 'wav'){

								$result = 0;

								$goal_path = $sound_path . basename( pdate("Y-n-d_H:i:s").".wav");  

								if(move_uploaded_file($_FILES['myfile']['tmp_name'], $goal_path))  
								{  
								$result = 1;  
								
								}

								if(file_exists($goal_path)){
									//echo pdate("Y-n-d_H:i:s").'.wav uploaded successfully.';
								$sql = "INSERT INTO userfiles (uid, file, date) VALUES ('".$id."', '".$goal_path."', '".time()."')";

									if ($conn->query($sql) === TRUE) {
										
										echo json_encode(array('status'=>1,'dir'=>"http://systemsms.ir/api/".$goal_path,'msg'=>'آپلود شد'), JSON_UNESCAPED_UNICODE);
									} else {
										echo json_encode(array('status'=>0,'msg'=>'مشکل در ذخیره کردن در دیتا بیس'), JSON_UNESCAPED_UNICODE);
									}
								}
							}else{
								echo json_encode(array('status'=>0,'msg'=>'فرمت اید wav باشد'), JSON_UNESCAPED_UNICODE);         
							}
					}else{
						echo json_encode(array('status'=>0,'msg'=>'لطفا دوباره سعی کنید'), JSON_UNESCAPED_UNICODE); 
					}
				
			} else {
				//echo "0 results";
				$data = array("userstats" => "0" ,"msg" => "token is invalide" );
				echo json_encode($data );
			}

	




?>