$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
"; //echo($customername); // header("Location: admin1.php"); } else { echo "Error uploading {$file_name}
"; } } 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); // Define new dimensions $newWidth = 600; $newHeight = 600; // 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, 50); // Free up memory imagedestroy($source); imagedestroy($thumb); //image is resized next step watermark // Ladataan pääkuva ja vesileimalogo $mainImg = imagecreatefromjpeg($urls); $watermark = imagecreatefrompng('raccoon.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
"; //echo($customername); // header("Location: admin1.php"); // $_POST["files[]"] = ""; } else { echo "Error uploading {$file_name}
"; } } } else { // If file extension not valid echo "Error uploading {$file_name} "; echo "({$file_ext} file type is not allowed)
"; } } } else { // If no files selected echo "No files selected."; } }else{ echo("dir doesnt exist"); } echo($customerview); }