$var: ${$var}
"; } $pnum = intval($pnum); //echo "packet ".$pnum; //echo " id ".$id; //echo $id."gggg".$did." pnum ".$pnum; //return; //$num = ShortToHexString($pnum); //zeropad(dechex($pnum), 2); $num = intval($pnum); switch ($pnum) { case 17: ImageNote($num, $taskid, $img); $buf = pack("CC", 17,1); echo base64_encode($buf); break; case 19: AudioNote($num, $taskid, $aud, $cpid); $buf = pack("CC", 19,1); echo base64_encode($buf); break; case 33: WriteLog($accid, $text); $buf = pack("CC", 33,1); echo base64_encode($buf); break; } function base64_to_jpeg( $inputfile, $outputfile ) { /* read data (binary) */ $ifp = fopen( $inputfile, "rb" ); $imageData = fread( $ifp, filesize( $inputfile ) ); fclose( $ifp ); /* encode & write data (binary) */ $ifp = fopen( $outputfile, "wb" ); fwrite( $ifp, base64_decode( $imageData ) ); fclose( $ifp ); /* return output filename */ return( $outputfile ); } function base64_to_audio( $inputdata, $outputfile ) { /* read data (binary) */ /* encode & write data (binary) */ $ifp = fopen( $outputfile, "wb" ); fwrite( $ifp, base64_decode( $inputdata ) ); fclose( $ifp ); /* return output filename */ return( $outputfile ); } function AudioNote($num, $taskid, $aud, $cpid) { global $link; // echo "AudioNote"; // return; $buf = pack("C*", 16); $companyID = getCompanyByTask($taskid)[0]; $project_id = getProjectIDByTask($taskid); $rootPath = $_SERVER['DOCUMENT_ROOT']; $companyPath = $rootPath."/data/$companyID"; $projectPath = $companyPath."/$project_id"; $imgpath = $projectPath."/$taskid/"; $err = 0; //echo base64_encode($buf."ImageNote comp $companyID pr $project_id path $imgpath err $err"); //return; $imagedata = base64_decode($aud); //$im = imagecreatefromstring($imagedata); if ($imagedata !== false) { if(!is_dir($companyPath)) { mkdir($companyPath); } if(!is_dir($projectPath)) { mkdir($projectPath); } if(!is_dir($imgpath)) { mkdir($imgpath); } } else { $err = 1; } $date = date("Y-m-d-H-i-s"); $path = $imgpath."aud".$date.".mp3"; //echo $path; $f = fopen($path, 'x'); if (!$f) { $err = 2; //return false; } else { $bytes = fwrite($f, $imagedata); fclose($f); // return $bytes; } //$str = "ImageNote comp $companyID pr $project_id path $imgpath err $err"; //echo $str; $size = sizeof($imagedata); $sizeaud = sizeof($aud); // echo "AudioNote size $size err $err sizeaud $sizeaud $imagedata"; //echo base64_encode($buf."ImageNote size $size"); } function ImageNote($num, $taskid, $img) { global $link; // $buf = pack("C*", 16); /** * @var $task Task */ $task = Task::Find($taskid); if ($task) { $companyID = getCompanyByTask($taskid)[0]; $project_id = $task->input_id;// getProjectIDByTask($taskid); $rootPath = $_SERVER['DOCUMENT_ROOT']; $companyPath = "/data/$companyID"; $projectPath = $companyPath . "/$project_id"; $relativeImgpath = $projectPath . "/$taskid/"; $imgpath = $rootPath.$relativeImgpath; $asusgId = $task->asusg_job_mapped_id; $date = date("Y-m-d-H-i-s"); if ($asusgId) { $str = "select asusg_job_uuid from asusg_job2launch where id= $asusgId"; $query = mysqli_query($link, $str); if ($res = mysqli_fetch_row($query)) { $uuid = $res[0]; require_once "curlexec.php"; $dict = array(); $domain = $_SERVER['SERVER_NAME']; $remoteImgPath = "http://".$domain.$relativeImgpath; $path = $remoteImgPath . "image" . $date . ".jpg"; $dict['photos_list'] = $path; $dict['id_work'] = $uuid; $url = "http://qaplatform.digitaldepot.ru:8085/Thingworx/Things/2050UserLibraryExp/Services/add_photos_work_v2"; $result = CURLrequestPOST($url, ["AppKey: 33cd23bb-3b03-4638-afef-7104a13e9211"], $dict); WriteLog("TWX Add_photos_work_v2 input ".json_encode($dict), $result); } } $err = 0; //echo base64_encode($buf."ImageNote comp $companyID pr $project_id path $imgpath err $err"); //return; $imagedata = base64_decode($img); $im = imagecreatefromstring($imagedata); if ($im !== false) { if (!is_dir($rootPath.$companyPath)) { mkdir($rootPath.$companyPath); } if (!is_dir($rootPath.$projectPath)) { mkdir($rootPath.$projectPath); } if (!is_dir($imgpath)) { mkdir($imgpath); } } else { $err = 1; } $path = $imgpath . "image" . $date . ".jpg"; // echo $path; $f = fopen($path, 'x'); if (!$f) { $err = 2; //return false; } else { $bytes = fwrite($f, $imagedata); fclose($f); // return $bytes; } //$str = "ImageNote comp $companyID pr $project_id path $imgpath err $err"; //echo $str; // $size = sizeof($img); //echo base64_encode($buf."ImageNote size $size"); } } ?>