-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
72 lines (69 loc) · 2.56 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
if(isset($_POST['button'])){
$imgUrl = $_POST['imgurl'];
$ch = curl_init($imgUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$downloadImg = curl_exec($ch);
curl_close($ch);
header('Content-type: image/jpg');
header('Content-Disposition: attachment;filename="thumbnail.jpg"');
echo $downloadImg;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thumbnail Downloader</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<header>Download Thumbnail</header>
<div class="url-input">
<span class="title">Paste video url:</span>
<div class="field">
<input type="text" placeholder="https://youtu.be/kraZG02x8Ks" required>
<input class="hidden-input" type="hidden" name="imgurl">
<span class="bottom-line"></span>
</div>
</div>
<div class="preview-area">
<img class="thumbnail" src="" alt="">
<i class="icon fas fa-cloud-download-alt"></i>
<span>Paste video url to see preview</span>
</div>
<button class="download-btn" type="submit" name="button">Download Thumbnail</button>
</form>
<script>
const urlField = document.querySelector(".field input"),
previewArea = document.querySelector(".preview-area"),
imgTag = previewArea.querySelector(".thumbnail"),
hiddenInput = document.querySelector(".hidden-input"),
button = document.querySelector(".download-btn");
urlField.onkeyup = ()=>{
let imgUrl = urlField.value;
previewArea.classList.add("active");
button.style.pointerEvents = "auto";
if(imgUrl.indexOf("https://www.youtube.com/watch?v=") != -1){
let vidId = imgUrl.split('v=')[1].substring(0, 11);
let ytImgUrl = `https://img.youtube.com/vi/${vidId}/maxresdefault.jpg`;
imgTag.src = ytImgUrl;
}else if(imgUrl.indexOf("https://youtu.be/") != -1){
let vidId = imgUrl.split('be/')[1].substring(0, 11);
let ytImgUrl = `https://img.youtube.com/vi/${vidId}/maxresdefault.jpg`;
imgTag.src = ytImgUrl;
}else if(imgUrl.match(/\.(jpe?g|png|gif|bmp|webp)$/i)){
imgTag.src = imgUrl;
}else{
imgTag.src = "";
button.style.pointerEvents = "none";
previewArea.classList.remove("active");
}
hiddenInput.value = imgTag.src;
}
</script>
</body>
</html>