gpt4 book ai didi

javascript - 如何将一个文件上传按钮的内容传递到另一个页面?

转载 作者:行者123 更新时间:2023-11-28 00:02:07 26 4
gpt4 key购买 nike

我是 PHP 新手。我有一个从系统上传文件的按钮。我使用 javascript,当用户上传文件时,它会自动重定向到网络表单。在网络表单上我使用三个字段。第一个是日期,第二个是标题,第三个是文件上传按钮。现在我想将我的文件内容传递给这个按钮。这可能吗?

我的上传文件按钮

enter image description here

上传文件后的我的表单

enter image description here

我想将文件、日期和标题存储在数据库中。为了节省用户的时间,我想传递文件内容。

我该怎么做?

请帮助我

按钮代码

<html>
<head>
<script>
function setup() {
document.getElementById('buttonid').addEventListener('click', openDialog);
function openDialog() {
document.getElementById('fileid').click();
}
document.getElementById('fileid').addEventListener('change', submitForm);
function submitForm() {
document.getElementById('formid').submit();
}
}
</script>
</head>
<body onload="setup()">
<form id='formid' action="mb.php" method="POST" enctype="multipart/form-data">
<input id='fileid' type='file' name='filename' hidden/>
<input id='buttonid' type='button' value='Upload MB' />
<input type='submit' value='Submit' hidden="" />
</form>
</body>
</html>

我的表单代码

mb.php

<?php

session_start();

//$user_id = $_SESSION['uid'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra-daily";

$conn = new mysqli($servername, $username, $password, $dbname);
//$id2 = $_GET['id'];
$sql="SELECT pacra_teams.title as 'teamTitle', og_users.display_name, og_users.id
FROM og_users
LEFT JOIN pacra_teams
ON pacra_teams.id = og_users.team_id
Where og_users.id = 20 ";
$result = $conn->query($sql);
$row = $result->fetch_object();

?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Upload Morning Briefing</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="js/jquery-ui.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.js"></script>

<script>
$(document).ready(function() {
$("#mydate").datepicker({
dateFormat: "dd-M-y",
onSelect: function(dateText, inst) {
$("#dt_title input[type='text']").val($("#dt_title input[type='text']").attr('data-title')+dateText);
}
}).datepicker("setDate", new Date());
});
</script>

</head>
<body>

<form action="up_mb.php" method="POST" enctype="multipart/form-data">
<div style="margin:auto; width:auto" align="center">
<table width="547" class="tblbdr" >
<tr>
<td height="23" colspan="6" class="head"><p> Morning Briefing </p></td>
</tr>
<tr> <td height="10"></td></tr>
<tr><td class="celltext"><b>Date:</b> </td> <td><input name="mydate" type="text" id="mydate" style="width:300px" readonly> </td></tr>
<tr>

<tr><td class="celltext"><b>Title: </b><br> </td>

<td class="celltext" style="width:200px" > <span id="dt_title"> <input name="title" type="text" value=" MB |
<?php echo $row->teamTitle;?> | <?php echo $row->display_name; ?> | <?php echo date("d-M-y");?>"
data-title="MB | <?php echo $row->teamTitle;?> | <?php echo $row->display_name;?> | " style="width:300px"/ readonly> </span> </td> </tr>
</tr>
<td class="celltext"><b>Upload File:</b></td>
<td colspan="4" bordercolorlight="#006666">
<input type="file" name="myfile" id="myfile" width="100%" size=80/>

<!-- <input type="file" name="files[]" multiple style="width:300px"/> -->
</td></tr>
<td><input type="submit" value="Save"/> </td> <td> </td>
<td width="151">

</td>
<tr>
<td height="12">
</td>
<td width="290">

</td> </tr>
</table>
</div>
</form>

</body>
</html>

最佳答案

出于安全原因,无法设置上传字段的文件

但是您可以使用第一个按钮将文件发送到服务器,然后使用第二个表单添加有关此上传的信息,这取决于您想如何处理这些数据

关于javascript - 如何将一个文件上传按钮的内容传递到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31696585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com