如何先上传文件然后提交到insertQuestion.php?

时间:2012-04-06 13:17:33

标签: php javascript html ajax

我有一个脚本,它上传一个名为upload_file.php的文件。问题是虽然我已经有一个页面(QandATable.php)提交的表单操作(insertQuestion.php)。所以我想知道的是如何在后台发布upload_php所以当用户提交表单时,它会将用户导航到insertQuestion.php页面,但是它会在后台将文件位置发布到uplodad_file.php页面?

下面是表单操作和提交按钮:

<form id="QandA" action="insertQuestion.php" method="post" enctype="multipart/form-data">

<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" /></p>

</form>

更新:

如果我想在后台将整个表单发布到createSession.php和upload_files.php,下面的AJAX是否有效?

         function submitform()
{
    var fieldvalue = $("#QandA").val();
    $.post("createSession.php", $("#QandA").serialize() ,function(data){
        var QandAO = document.getElementById("QandA");
    $.post("upload_files.php", $("#QandA").serialize() ,function(data){
        var QandAO = document.getElementById("QandA");
        QandAO.submit();
    });  
    alert("Your Details for this Session has been submitted"); 
}

1 个答案:

答案 0 :(得分:0)

据我了解,您可以使用header()

QandATable.php

<form action='upload.php' ...>
// you form details
</form>

upload.php的

ob_start();
 // do uploads 
header('Location:insertQuestion.php');
exit();