i hv工作代码,我通过将其插入文本框来复制值
我想将我上传图片链接的值之一复制到用户剪贴板,方法是先将其保存到一个php变量,然后回显到html文本框。但是我在通过html文本框复制它时遇到问题,因此我想将其保存到html中的变量,然后将其复制到用户的clipboad
any one here which can suggest a working method here's my working code
<?php
//upload.php
if($_FILES["file"]["name"] != '')
{
$test = explode('.', $_FILES["file"]["name"]);
$ext = end($test);
$name = rand(100, 999999999) . '.' . $ext;
$location = './upload/' . $name;
$url= 'www.chat.com/upload/' . $name;
move_uploaded_file($_FILES["file"]["tmp_name"], $location);
// echo '<img src="'.$location.'" height="150" width="225" class="img-thumbnail" />';
// echo "\n\n\n\n$url";
} else {
$url = "";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Copy & Paste YOUR IMAGE LINK </title>
<style>
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 55px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 15px 2px;
cursor: pointer;
}
</style>
</head>
<body>
<input type="text" value="<?php echo $url; ?>" id="myInput">
<button onclick="myFunction()"><h4 style="color:green;font-size:15px;"><b>Copy Img link</b></h4></button>
<script>
function myFunction() {
let inputEl = document.getElementById("myInput");
inputEl.select(); // Select element
inputEl.setSelectionRange(0, inputEl.value.length); // select from 0 to element length
const successful = document.execCommand('copy'); // copy input value, and store success if needed
if(successful) {
// alert("Copied IMAGE URL PASTE IT TO SENDER : " + inputEl.value);
} else {
// ...
}
}
</script>
</body>
</html>
您可以尝试使用以下JS函数吗?