根据附件或者图片链接上传到服务器并返回链接到粘贴板
<tr>
<td width='16%' height=25 bgcolor='ffffff'>上传附件</td>
<td bgcolor='ffffff'><script type="text/javascript" src="/ziyuan/js/clipboard.min.js"></script>
<p>
附件:
<input type="text" id="file" value="" size="50">
<input type="button" onclick="UpladFile()" value="上传">
<input type="text" value="" id="Enclosure" size="50"> <input type="button" id="copy" value="复制"><span
style="color:red">[ rar | zip | pdf | doc | xls | xlsl ]</span>
</p>
<p>
图片:
<input type="text" id="file1" value="" size="50">
<input type="button" onclick="UpladFile1()" value="上传">
<input type="text" value="" id="Enclosure1" size="50"> <input type="button" id="copy" value="复制">
</p>
<script>
function UpladFile() {
var file = document.getElementById("file").value; // js 获取文件对象
if(file==""){
alert("无效附件路径");
return;
}
$("#Enclosure").value="";
var url = "/e/extend/api/index.php?m=uplaod&c=uploadfiles&token=ojPVw$*gzHUrs!N^";
$.ajax({
type:"post",
url: url,
data: {"file":file},
dataType: "JSON",
success: function(data){
if(data.Code==201){
alert(data.Msg);
}else{
$("#Enclosure").val(data.File);
copyText(data.File, function (){alert('上传成功,并成功复制到剪切板')})
}
}
});
}
function UpladFile1() {
var file = document.getElementById("file1").value; // js 获取文件对象
if(file==""){
alert("无效附件路径");
return;
}
$("#Enclosure1").value="";
var url = "/e/extend/api/index.php?m=uplaod&c=uploadpic&token=ojPVw$*gzHUrs!N^";
$.ajax({
type:"post",
url: url,
data: {"file":file},
dataType: "JSON",
success: function(data){
if(data.Code==201){
alert(data.Msg);
}else{
$("#Enclosure1").val(data.File);
copyText(data.File, function (){alert('上传成功,并成功复制到剪切板')})
}
}
});
}
// 复制的方法
function copyText(text, callback){ // text: 要复制的内容, callback: 回调
var tag = document.createElement('input');
tag.setAttribute('id', 'cp_hgz_input');
tag.value = text;
document.getElementsByTagName('body')[0].appendChild(tag);
document.getElementById('cp_hgz_input').select();
document.execCommand('copy');
document.getElementById('cp_hgz_input').remove();
if(callback) {callback(text)}
}
// 点击按钮调用复制
if (document.getElementById('copy')!=undefined) {
document.getElementById('copy').onclick = function (){
var content=document.getElementById("Enclosure").value;
if(content==""){
return;
}
copyText(content, function (){console.log('复制成功')})
}
}
</script>
</td>
</tr>
<?php
//uploadpic.php 文件
$picdata = array(
'upname'=>$file,
'imgurl'=>$basepath.$save_dir,
'biaoqianid'=>16,
'time'=>date("Y-m-d h:i:s")
);
$api->insert("upload_files",$picdata);
// $basepath = is_https_i() ? "https://" . $_SERVER['SERVER_NAME'] . '/' : "http://" . $_SERVER['SERVER_NAME'] . '/';
$res = array(
"Code" => 101,
"File"=>"<img src=\"".$basepath.$save_dir."\">",
"Msg" => "文件上传成功"
);
$api->json($res);
exit(0);
?>