Test visual studio git

This commit is contained in:
2026-11-13 15:39:48 +02:00
parent 9634551a68
commit ae6a212787
67 changed files with 274 additions and 189 deletions
+75 -171
View File
@@ -1,178 +1,17 @@
<?php
include "db.php";
if(isset($_POST['submit'])) {
$customername = $_POST["name"];
$customerpass = $_POST["pass"];
$customerphone = $_POST["phone"];
$customeremail = $_POST["email"];
$stmt = $mysqli ->prepare("SELECT * FROM products ");
$stmt = $mysqli ->prepare("SELECT usersname FROM users WHERE usersname = ? ");
$stmt -> bind_param("s",$customername);
$stmt -> execute();
$stmt->store_result();
if($stmt->num_rows == 0){
$hashed = password_hash($customerpass, PASSWORD_DEFAULT);
$priv = "spectator";
$stmt = $mysqli->prepare("INSERT INTO users (usersname,userspass,userspriv,usersphone,usersemail) VALUES (?,?,?,?,?)");
$stmt->bind_param("sssss", $customername,$hashed,$priv,$customerphone,$customeremail);
$stmt->execute();
}
mkdir("uploads/".$customername);
$customerview = "http://localhost/imageGalleryv2/kirjaudu.php";
// Configure upload directory and allowed file types
$upload_dir = "uploads/".$customername.'/';
$allowed_types = array('jpg', 'png', 'jpeg', 'gif');
// Define maxsize for files i.e 2MB
$maxsize = 2 * 10024 * 10024;
//checks if directory exist before continuen
if(is_dir("uploads/".$customername)){
// Checks if user sent an empty form
if(!empty(array_filter($_FILES['files']['name']))) {
// Loop through each file in files[] array
foreach ($_FILES['files']['tmp_name'] as $key => $value) {
$file_tmpname = $_FILES['files']['tmp_name'][$key];
$file_name = $_FILES['files']['name'][$key];
$file_size = $_FILES['files']['size'][$key];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
// Set upload file path
$filepath = $upload_dir.$file_name;
// Check file type is allowed or not
if(in_array(strtolower($file_ext), $allowed_types)) {
// If file with name already exist then append time in
// front of name of the file to avoid overwriting of file
if(file_exists($filepath)) {
$filepath = $upload_dir.time().$file_name;
if( move_uploaded_file($file_tmpname, $filepath)) {
$urls = $upload_dir.$file_name;
$stmt = $mysqli->prepare("INSERT INTO images (imagesusers,imagesurls,imagesname) VALUES (?,?,?)");
$stmt->bind_param("sss", $customername,$urls,$file_name);
$stmt->execute();
echo "{$file_name} successfully uploaded <br />";
//echo($customername);
// header("Location: admin1.php");
}
else {
echo "Error uploading {$file_name} <br />";
}
}
else {
if( move_uploaded_file($file_tmpname, $filepath)) {
$urls = $upload_dir."/".$file_name;
//resize picture on upload dont see any reason to keep original picturefiles on server at this moment
$source = imagecreatefromjpeg($urls);
list($width, $height) = getimagesize($urls);
list($old_width, $old_height) = getimagesize($urls);
// Define new dimensions
/*$newWidth = 400;
$newHeight = 400;
*/
$max_width = 400;
if ($old_width > $max_width) {
$ratio = $old_width / $max_width;
$newWidth = $max_width;
$newHeight = (int) round($old_height / $ratio);
} else {
$newWidth = $old_width;
$newHeight = $old_height;
}
// Create a blank true-color image
$thumb = imagecreatetruecolor($newWidth, $newHeight);
// Resize and copy
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// Save output
imagejpeg($thumb, $urls, 80);
// Free up memory
imagedestroy($source);
imagedestroy($thumb);
//image is resized next step watermark
// Ladataan pääkuva ja vesileimalogo
$mainImg = imagecreatefromjpeg($urls);
$watermark = imagecreatefrompng('styles/tes.png');
// Haetaan kuvien mitat
$mainWidth = imagesx($mainImg);
$mainHeight = imagesy($mainImg);
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);
// Lasketaan sijainti (oikea alakulma, 20px marginaali)
$dstX = $mainWidth - $watermarkWidth - 20;
$dstY = $mainHeight - $watermarkHeight - 20;
// Kopioidaan vesileima pääkuvan päälle säilyttäen alfa-kanava (läpinäkyvyys)
imagecopy($mainImg, $watermark, $dstX, $dstY, 0, 0, $watermarkWidth, $watermarkHeight);
// Tallennetaan valmis kuva
imagejpeg($mainImg, $urls, 90);
// Vapautetaan muisti
imagedestroy($mainImg);
imagedestroy($watermark);
//$urls = "images/".$file_name;
$stmt = $mysqli->prepare("INSERT INTO images (imagesusers,imagesurls,imagesname) VALUES (?,?,?)");
$stmt->bind_param("sss", $customername,$urls,$file_name);
$stmt->execute();
echo "{$file_name} successfully uploaded <br />";
//echo($customername);
// header("Location: admin1.php");
// $_POST["files[]"] = "";
}
else {
echo "Error uploading {$file_name} <br />";
}
}
}
else {
// If file extension not valid
echo "Error uploading {$file_name} ";
echo "({$file_ext} file type is not allowed)<br / >";
}
}
}
else {
// If no files selected
echo "No files selected.";
}
}else{
echo("dir doesnt exist");
}
echo("<br>");
echo("osoite: ".$customerview . "<br>");
echo("Käyttäjä: ". $customername . "<br>");
echo("Salasana: ". $customerpass);
}
$result = $stmt->get_result();
//$stmt->store_result();
$products=array();
while($row = mysqli_fetch_assoc($result)) {
$products[]=$row;
}
print_r($products);
?>
<!DOCTYPE html>
@@ -185,10 +24,13 @@ imagedestroy($watermark);
</head>
<body>
<div id="response">
</div>
<!-- multipart/form-data ensures that form
data is going to be encoded as MIME data -->
<form action="" method="POST"
<form id="form" action="" method="POST"
enctype="multipart/form-data">
<h2>Upload Files</h2>
@@ -208,7 +50,7 @@ imagedestroy($watermark);
<p>
Valitse tiedostot
</p>
<input type="file" name="files[]" multiple>
<input id="filesInput" type="file" name="files[]" multiple>
<br><br>
@@ -217,4 +59,66 @@ imagedestroy($watermark);
</form>
</body>
<script>/*
const form = document.getElementById('form');
form.addEventListener("click", function(event){
event.preventDefault();
const formattedFormData = new FormData(form);
let formData = new FormData([form]);
console.log(formattedFormData);
});*/
let div = document.getElementById("response");
const uploaded = [];
let text;
form.onsubmit = async (e) => {
e.preventDefault();
const data = new FormData(form);
const data1 = new FormData(form);
data1.delete("files[]");
try{
let response1 = await fetch('/imageGalleryv2/register.php', {
method: 'POST',
body: data1
}).then(response => response1.json() ).then(result=>{
/*uploaded.push(result.response)*/
text=document.createTextNode(result.response1);
div.appendChild(text);
});
} catch (e){
}
name = data.get("name");
const fileinput = document.getElementById("filesInput");
//console.log(fileinput.files);
let s = "kukkuu";
for(var f of fileinput.files){
data.set("files[]",f)
try{
let response = await fetch('/imageGalleryv2/test.php', {
method: 'POST',
body: data
}).then(response => response.json() ).then(result=>{
/*uploaded.push(result.response)*/
text=document.createTextNode(result.response);
div.appendChild(text);
});
} catch (e){
}
}
const values = [...data.entries()];
};
</script>
</html>
+15 -18
View File
@@ -40,7 +40,7 @@ while($row = mysqli_fetch_assoc($result)){
exit;}
echo("moi");
?>
@@ -75,27 +75,24 @@ exit;}
</body>
</html>
<script>
let arr = [];
function add(name, elem){
if(elem.classList.contains("active")){
console.log("--|--");
for(i = 0 ; i < elem.classList.length; i ++){
console.log(elem.classList[i]);
if(elem.classList[i] == "active"){
elem.classList.remove("active");
}
let arr = [];
function add(name, elem){
if(elem.classList.contains("active")){
console.log("--|--");
for(i = 0 ; i < elem.classList.length; i ++){
console.log(elem.classList[i]);
if(elem.classList[i] == "active"){
elem.classList.remove("active");
}
}
}else{
elem.classList.add("active");
}
}else{
elem.classList.add("active");
}
if (arr.includes(name)) {
arr = arr.filter(item => item !== name);
+20
View File
@@ -0,0 +1,20 @@
<?php
include "db.php";
$customername = $_POST["name"];
$customerpass = $_POST["pass"];
$customerphone = $_POST["phone"];
$customeremail = $_POST["email"];
$stmt = $mysqli ->prepare("SELECT usersname FROM users WHERE usersname = ? ");
$stmt -> bind_param("s",$customername);
$stmt -> execute();
$stmt->store_result();
if($stmt->num_rows == 0){
$hashed = password_hash($customerpass, PASSWORD_DEFAULT);
$priv = "spectator";
$stmt = $mysqli->prepare("INSERT INTO users (usersname,userspass,userspriv,usersphone,usersemail) VALUES (?,?,?,?,?)");
$stmt->bind_param("sssss", $customername,$hashed,$priv,$customerphone,$customeremail);
$stmt->execute();
}
?>
+164
View File
@@ -0,0 +1,164 @@
<?php
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include "db.php";
$customername = $_POST["name"];
//echo($customername);
if(!is_dir("uploads/".$customername)){mkdir("uploads/".$customername);}
$customerview = "http://localhost/imageGalleryv2/kirjaudu.php";
// Configure upload directory and allowed file types
$upload_dir = "uploads/".$customername.'/';
$allowed_types = array('jpg', 'png', 'jpeg', 'gif');
// Define maxsize for files i.e 2MB
$maxsize = 2 * 10024 * 10024;
//checks if directory exist before continuen
if(is_dir("uploads/".$customername)){
// Checks if user sent an empty form
if(!empty(array_filter($_FILES['files']['name']))) {
// Loop through each file in files[] array
foreach ($_FILES['files']['tmp_name'] as $key => $value) {
$file_tmpname = $_FILES['files']['tmp_name'][$key];
$file_name = $_FILES['files']['name'][$key];
$file_size = $_FILES['files']['size'][$key];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
// Set upload file path
$filepath = $upload_dir.$file_name;
// Check file type is allowed or not
if(in_array(strtolower($file_ext), $allowed_types)) {
// If file with name already exist then append time in
// front of name of the file to avoid overwriting of file
if(file_exists($filepath)) {
$filepath = $upload_dir.time().$file_name;
if( move_uploaded_file($file_tmpname, $filepath)) {
$urls = $upload_dir.$file_name;
$stmt = $mysqli->prepare("INSERT INTO images (imagesusers,imagesurls,imagesname) VALUES (?,?,?)");
$stmt->bind_param("sss", $customername,$urls,$file_name);
$stmt->execute();
echo json_encode(["response" =>$file_name ]) ;
//echo($customername);
// header("Location: admin1.php");
}
else {
echo "Error uploading {$file_name} <br />";
}
}
else {
if( move_uploaded_file($file_tmpname, $filepath)) {
$urls = $upload_dir.$file_name;
//resize picture on upload dont see any reason to keep original picturefiles on server at this moment
$source = imagecreatefromjpeg($urls);
list($width, $height) = getimagesize($urls);
list($old_width, $old_height) = getimagesize($urls);
// Define new dimensions
/*$newWidth = 400;
$newHeight = 400;
*/
$max_width = 400;
if ($old_width > $max_width) {
$ratio = $old_width / $max_width;
$newWidth = $max_width;
$newHeight = (int) round($old_height / $ratio);
} else {
$newWidth = $old_width;
$newHeight = $old_height;
}
// Create a blank true-color image
$thumb = imagecreatetruecolor($newWidth, $newHeight);
// Resize and copy
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// Save output
imagejpeg($thumb, $urls, 80);
// Free up memory
imagedestroy($source);
imagedestroy($thumb);
//image is resized next step watermark
// Ladataan pääkuva ja vesileimalogo
$mainImg = imagecreatefromjpeg($urls);
$watermark = imagecreatefrompng('styles/tes.png');
// Haetaan kuvien mitat
$mainWidth = imagesx($mainImg);
$mainHeight = imagesy($mainImg);
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);
// Lasketaan sijainti (oikea alakulma, 20px marginaali)
$dstX = $mainWidth - $watermarkWidth - 20;
$dstY = $mainHeight - $watermarkHeight - 20;
// Kopioidaan vesileima pääkuvan päälle säilyttäen alfa-kanava (läpinäkyvyys)
imagecopy($mainImg, $watermark, $dstX, $dstY, 0, 0, $watermarkWidth, $watermarkHeight);
// Tallennetaan valmis kuva
imagejpeg($mainImg, $urls, 90);
// Vapautetaan muisti
imagedestroy($mainImg);
imagedestroy($watermark);
//$urls = "images/".$file_name;
$stmt = $mysqli->prepare("INSERT INTO images (imagesusers,imagesurls,imagesname) VALUES (?,?,?)");
$stmt->bind_param("sss", $customername,$urls,$file_name);
$stmt->execute();
// echo "{$file_name} successfully uploaded <br />";
//echo($customername);
// header("Location: admin1.php");
echo json_encode(["response" =>$file_name ]) ;
// $_POST["files[]"] = "";
}
else {
echo "Error uploading {$file_name} <br />";
}
}
}
else {
// If file extension not valid
echo "Error uploading {$file_name} ";
echo "({$file_ext} file type is not allowed)<br / >";
}
}
}
else {
// If no files selected
echo "No files selected.";
}
}else{
echo("dir doesnt exist");
}
// echo("<br>");
// echo("osoite: ".$customerview . "<br>");
// echo("Käyttäjä: ". $customername . "<br>");
//echo("Salasana: ". $customerpass);
// echo json_encode(["drivers" => $customername]);
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 978 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB