【发布时间】:2020-07-11 13:16:01
【问题描述】:
我有工作代码,我通过将值插入到 html 文本框来复制值 我现在的流程是
1-将图片url保存到php变量$url 2-然后将 $url 回显到 html 文本框然后 3-将其复制到用户的剪贴板
我只是想删除我的第二步,并希望以任何其他方式将其复制到剪贴板
我想将我的上传图片链接的值复制到用户剪贴板,方法是先将其保存到一个 php 变量,然后回显到 html 文本框。
但是我在通过 html 文本框复制它时遇到问题,所以我想将它保存到 html 中的变量,然后将其复制到用户的剪贴板。
这里有人可以提出一种工作方法吗? 这是我的工作代码:
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 = "";
}
风格:
.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;
}
HTML:
<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>
脚本:
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 {
// ...
}
}
【问题讨论】:
标签: php html variables copy clipboard