gpt4 book ai didi

javascript - 文件上传无法在单击文件时插入表单和查看

转载 作者:行者123 更新时间:2023-11-30 21:41:15 25 4
gpt4 key购买 nike

我已经为表单内的代码完成了文件上传,提交时表单应该插入到数据库中,但这并没有发生,我正在另一个页面中获取表格,当我点击特定文件时,它没有正确重定向到页面.

jobs.php

<div id="apply" class="overlay">
<div class="popup">
<a class="close" href="jobs.php">&times;</a>
<div class="content" style="margin-top: 20px;">
<form enctype="multipart/form-data" class="" action="upload.php" id="template-jobform" name="template-jobform" method="post" role="form" value="<?php echo htmlspecialchars($row['id']);?>">

<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="template-jobform-fname" id="name" placeholder="Enter your Name"/>
</div>
</div>
</div>

<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="template-jobform-email" id="email" placeholder="Enter your Email"/>
</div>
</div>
</div>

<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
<input type="phone" class="form-control" name="template-jobform-phone" id="mobile" placeholder="Mobile Number"/>
</div>
</div>
</div>


<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-briefcase fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" name="job_name" id="mobile" placeholder="Position Applying For"/>
</div>
</div>
</div>

<div class="form-group">

<div class="cols-sm-10">
<div class="input-group">

<input type="file"
class="filepond"
name="file"
multiple/>

<!-- <button type="submit" name="btn-upload">upload</button> -->
</div>
</div>
</div>


<?php
include('admin/config.php');
ini_set("display_errors", 1);


if(isset($_POST['btn-upload']) && $_POST['template-jobform-email']!= '' && $_POST['template-jobform-fname']!= '') {
$sql = "INSERT INTO apply_job (`template-jobform-fname`,`template-jobform-email`,`template-jobform-phone`,`job_name`) VALUES (?,?,?,?)";
$stmt = mysqli_prepare($db,$sql);
$stmt->bind_param("ssss", $_POST['template-jobform-fname'], $_POST['template-jobform-email'], $_POST['template-jobform-phone'],$_POST['job_name']);
$stmt->execute();
}
?>


<div class="form-group">
<button target="_blank" type="submit" name="btn-upload" class="btn btn-primary btn-lg btn-block">Apply</button>
</div>



</form>
<br /><br />
<?php
if(isset($_GET['success']))
{
?>
<label>File Uploaded Successfully... <a href="view.php">click here to view file.</a></label>
<?php
}
else if(isset($_GET['fail']))
{
?>
<label>Problem While File Uploading !</label>
<?php
}
else
{
?>
<label>Try to upload any files(PDF, DOC, EXE, VIDEO, MP3, ZIP,etc...)</label>
<?php
}
?>
</div>
</div>
</div>

upload.php

 if(isset($_POST['btn-upload']))
{

$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="admin/uploads/";

// new file size in KB
$new_size = $file_size/1024;
// new file size in KB

// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case

$final_file=str_replace(' ','-',$new_file_name);

if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO apply_job(file,type,size) VALUES('$final_file','$file_type','$new_size')";
mysqli_query($db,$sql);
echo $sql;
?>
<script>
alert('successfully uploaded');
window.location.href='jobs.php?success';
</script>
<?php
}

?>

Image

如上图所示,当我单击 pdf 时,如何为文件设置正确的 pdf 路径以使其正确重定向。

最佳答案

乍一看,您的开场白form -tag 不遵循 HTML 标记语言限制。请注意,HTML(如 XML)需要标签的树结构,以免出现意外行为。示例:

  • 允许:<form><div></div></form>
  • 不允许:<div><form></div></form>

也许这可以修复重定向错误。

关于javascript - 文件上传无法在单击文件时插入表单和查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51439305/

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