Line Notify Send Picture File

Line Notify Send CTRL+V Picture File


<?php
$objConnect = mysqli_connect("localhost","root","password",$dbname) or die("Error Connect to Database");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="">
<meta charset="utf-8">
<script src="jquery-1.10.2.min.js"></script>
<script src="pasteimage.js"></script> 
<script language=JavaScript>
function check_length(frmMain)
{
if (frmMain.hdnCmd.value='Add')
 {
 frmMain.hdnCmd.value='Add'
 frmMain.submit();
 }
}
</script>

<script>
function paste(src) {
$(document.body).append("<img src='" + src + "' width='60%'><form name='frmMain' method='post' action='upimg.php'><input type='hidden' name='hdnCmd' value=''><input name='base64_data' type='hidden' value='" + src + "'> <input name='btnAdd' type='button' id='btnAdd' value='Upload'  OnClick='return check_length(frmMain);'></form>");
}
$(function() {
$.pasteimage(paste);
});
</script>

<?php
while(list($xVarName, $xVarvalue) = each($_GET)) {
     ${$xVarName} = $xVarvalue;
}
while(list($xVarName, $xVarvalue) = each($_POST)) {
     ${$xVarName} = $xVarvalue;
}
while(list($xVarName, $xVarvalue) = each($_FILES)) {
     ${$xVarName."_name"} = $xVarvalue['name'];
     ${$xVarName."_type"} = $xVarvalue['type'];
     ${$xVarName."_size"} = $xVarvalue['size'];
     ${$xVarName."_error"} = $xVarvalue['error'];
     ${$xVarName} = $xVarvalue['tmp_name'];
}
?>

</head> <body>
Take a screenshot and press CTRL+V to paste into this page and click upload.
<br>
<?php
function base64_to_jpeg($base64_string, $output_file) {
    // open the output file for writing
    $ifp = fopen( $output_file, 'wb' );
    // split the string on commas
    // $data[ 0 ] == "data:image/png;base64"
    // $data[ 1 ] == <actual base64 string>
    $dataa = explode( ',', $base64_string );
    // we could add validation here with ensuring count( $data ) > 1
    fwrite( $ifp, base64_decode( $dataa[ 1 ] ) );
    // clean up the file resource
    fclose( $ifp );
    return $output_file;
}
class LineNotify
{
  public function PushMessage($token, $body)
  {
    $result_ = "";
    $chOne = curl_init();
    curl_setopt( $chOne, CURLOPT_URL, "https://notify-api.line.me/api/notify");
    // SSL USE
    curl_setopt( $chOne, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt( $chOne, CURLOPT_SSL_VERIFYPEER, 0);
    //POST
    curl_setopt( $chOne, CURLOPT_POST, 1);
    curl_setopt( $chOne, CURLOPT_POSTFIELDS, $body);
    curl_setopt( $chOne, CURLOPT_FOLLOWLOCATION, 1);
    //ADD header array
    $headers = array( 'Content-type: multipart/form-data', 'Authorization: Bearer '.$token, );
    curl_setopt($chOne, CURLOPT_HTTPHEADER, $headers);
    //RETURN
    curl_setopt( $chOne, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec( $chOne );
    //Check error
    if(curl_error($chOne)) {
        $error_ = array('status' => "Error",'massage' => curl_error($chOne));
        $result_ = json_decode($error_, true);
    }
    else {
      $result_ = json_decode($result, true);
    }
    //Close connect
    curl_close( $chOne );
    return  $result_;
  }
}
if($_POST["hdnCmd"] == "Add")
{
$base64_data = $_POST['base64_data'];
$data = $_POST['base64_data'];

$img = 'img/'.$_SESSION['license'].'_'.date('Ymd_Hi').'.png';
$imgs = ''.$_SESSION['license'].'_'.date('Ymd_Hi').'.png';
base64_to_jpeg($data,$img);
$strSQLa="INSERT into img (file_name,fullname,complete,timeadd) VALUES('".$imgs."','".($_SESSION['fullname'])."','1',Now()); ";
$objQuerya = mysqli_query($objConnect,$strSQLa);
$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$file_name_with_full_path = 'C:\\xampp\htdocs\lineauto\img\\'.$imgs.'';
if (function_exists('curl_file_create')) {
  $cFile = curl_file_create($file_name_with_full_path);
} else {
  $cFile = '@'.realpath($file_name_with_full_path);
}
$post = array('message' => ''.$_SESSION['fullname'].' '.date('Y-m-d_H:i:s').'','imageFile'=> $cFile);
(LineNotify::PushMessage($token,$post));
?>

<img src="img/<?=$imgs;?>" width='60%'> <br><?=$_SESSION['fullname'];?> Update Time <?=Date('Y-m-d H:i:s');?>
<?php
}
?>

 <?php
$strSQLaaaa = "SELECT * FROM img where upper(fullname) LIKE '".$_SESSION['fullname']."' ORDER BY id desc limit 1";
$objQueryaaaaa = mysqli_query($objConnect,$strSQLaaaa) or die ("Error Query [".$strSQLaaaa."]");
while($objResult = mysqli_fetch_array($objQueryaaaaa))
{
?>
<br><?=$objResult['timeadd'];?> <img src="img/<?=$objResult['file_name'];?>" width='20%'> <?=$objResult['fullname'];?> <?php if($objResult['complete']==="1"){ echo 'Complete'; } else{ echo 'No'; }?>
<br> <?php }  ?>  </body> </html>



แสดงความคิดเห็น

0 ความคิดเห็น