From a31195affd7fdcb3f71f14cd5e10297b7acd3180 Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Sun, 15 Jan 2023 02:11:44 +0100 Subject: [PATCH] qr uload --- .env.hope-fly | 3 +- .env.local | 3 +- php/php-dog/upload.php | 65 ++++++++++++++++++++++++++++++++++++--- src/components/Profil.tsx | 2 ++ src/services/CreateQr.ts | 27 ++++++++-------- 5 files changed, 79 insertions(+), 21 deletions(-) diff --git a/.env.hope-fly b/.env.hope-fly index 227dd7b..2bf6671 100644 --- a/.env.hope-fly +++ b/.env.hope-fly @@ -1 +1,2 @@ -REACT_APP_PHP_ROOT = https://hope-fly.de/dog/php-dog/ +REACT_APP_PHP_ROOT = "https://hope-fly.de/dog/php-dog/" +REACT_APP_WWW_ROOT = "https://hope-fly.de/dog/" diff --git a/.env.local b/.env.local index c13bed9..8ab2952 100644 --- a/.env.local +++ b/.env.local @@ -1 +1,2 @@ -REACT_APP_PHP_ROOT = http://localhost/dog/php-dog/ +REACT_APP_PHP_ROOT = "http://localhost/dog/php-dog/" +REACT_APP_WWW_ROOT = "http://localhost/dog/" diff --git a/php/php-dog/upload.php b/php/php-dog/upload.php index 8a340a7..cbe3e0e 100644 --- a/php/php-dog/upload.php +++ b/php/php-dog/upload.php @@ -5,10 +5,67 @@ header("Access-Control-Allow-Methods: POST"); header("Content-Type: application/json; charset=UTF-8"); header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); +require __DIR__ . '/classes/Database.php'; +require __DIR__ . '/classes/lib.php'; + + +function deleteOldPic($qr_id, $qr) +{ + // get old pic_path + try + { + echo "qr_id ". $qr_id . "\n"; + echo "qr_set ". $qr . "\n"; + echo "isset qr_set ". isset($qr) . "\n"; + $db_connection = new Database(); + //$conn = $db_connection->dbConnection(); + + echo "db_connection ". $db_connection . "\n"; + //echo "conn ". $conn . "\n"; + + + + // $fetch_user_qr_id = + // "SELECT id, qr_code, picture FROM `dogs` WHERE `qr_id`=:qr_id"; + // $query_stmt = $conn->prepare($fetch_user_qr_id); + // echo "query_stmt ". $query_stmt . "\n"; + // $query_stmt->bindValue(':qr_id', $qr_id,PDO::PARAM_STR); + // echo "bindValue ". "\n"; + // $query_stmt->execute(); + // echo "execute ". "\n"; + + // // IF THE dog IS FOUNDED BY qr_id + // if($query_stmt->rowCount()) + // { + // $row = $query_stmt->fetch(PDO::FETCH_ASSOC); + // $file2del = "../uploads/"; + // if($qr_set) + // { + // $file2del += $row["qr_code"]; + // } + // else + // { + // $file2del += $row["picture"]; + // } + // if (file_exists($file2del)) + // { + // unlink($file2del); + // } + // $result = new CMsg(1,200,'get old pic_path',null,$row); + // } + // else + // { + // $result = new CMsg(0,422,'no dog',null); + // } + } + catch(PDOException $e) + { + $result = new CMsg(0,500,"deleteOldPic ".$e->getMessage()); + echo $result->jsonarray(); + } +} try { - - session_start(); // $resp = json_decode(' @@ -24,8 +81,6 @@ try { // $_SESSION["user"] = $resp["user"]; - require __DIR__ . '/classes/Database.php'; - require __DIR__ . '/classes/lib.php'; $result = new CMsg(0); @@ -63,7 +118,7 @@ try { echo $result->jsonarray(); return $result->jsonarray(); } - + deleteOldPic($user["qr_id"], $_POST["qr"]); $newFilename = getNewFilename($targetDir, $fileType, 20); // echo "newFilename ".$newFilename . "\n"; diff --git a/src/components/Profil.tsx b/src/components/Profil.tsx index f4bbceb..604bff8 100644 --- a/src/components/Profil.tsx +++ b/src/components/Profil.tsx @@ -81,6 +81,8 @@ function Profil()
{dog.data && } Bild ändern + {dog.data && } +
diff --git a/src/services/CreateQr.ts b/src/services/CreateQr.ts index b90f28e..808c119 100644 --- a/src/services/CreateQr.ts +++ b/src/services/CreateQr.ts @@ -24,8 +24,9 @@ const upload = (file: File): Promise => return uploadRes; }; -export default function CreateQr({qr_id}:{qr_id: string | undefined}) +export default async function CreateQr({qr_id}:{qr_id: string | undefined}) { + const WWW_ROOT: string = process.env.REACT_APP_WWW_ROOT!; const qrCode = new QRCodeStyling( { width: 200, @@ -33,7 +34,7 @@ export default function CreateQr({qr_id}:{qr_id: string | undefined}) type: 'canvas', image: "", - data: 'https://hope-fly.de/dog/'+ qr_id, + data: WWW_ROOT + qr_id, dotsOptions: { color: "#000", @@ -49,18 +50,16 @@ export default function CreateQr({qr_id}:{qr_id: string | undefined}) type: "extra-rounded", } }); + document.getElementById("canvas")!.innerHTML = ""; + qrCode.append(document.getElementById("canvas") as HTMLElement); - let canv: any = qrCode._canvas!.getCanvas() as HTMLCanvasElement; - canv.toBlob(({blob}:{blob: Blob | MediaSource}) => + let qr_el:HTMLCanvasElement = await qrCode._getElement() as unknown as HTMLCanvasElement; + let file: File; + + qr_el.toBlob((blob) => { - const file = URL.createObjectURL(blob); - console.log(blob); - console.log(file); // this line should be here - },'image/png'); - - - - -// upload(qrCode._svg as File); - console.log(qrCode); + file = new File([blob!], 'qr_blob.png', { type: 'image/png' }); + console.log(file); + upload(file); + }, 'image/png'); }