简体   繁体   English

从同一按钮执行PHP提交和Fileupload

[英]Doing PHP Submit and Fileupload from same button

I am writing a page where a user can fill out form data, select two files for upload, and then hit Submit to pass the form data into the PHP page, and also the two files will be uploaded. 我正在写一个页面,用户可以在其中填写表单数据,选择两个文件进行上传,然后单击Submit将表单数据传递到PHP页面,这两个文件也将被上传。

The problem is the submit button seems to be able to only be either a 'submit' or a 'File_Upload'. 问题是,提交按钮似乎只能是“提交”或“ File_Upload”。 It can't do both... or can it? 它不能两者兼而有之吗?

Here is the gyst of HTML file (Just enough to get the point across... I hope) 这是HTML文件的精妙之处(刚好可以使您理解重点...我希望)

  <form class='form' name="frm_new_session" method="POST" enctype="multipart/form-data">  
    <div class='frm_row'>  
        <label>Title</label>  
        <input id="titleF" type='text' name="title" size='50' />  
        <input type="hidden" name="_chkuser" value="1"/>  
    </div>  
    <div class='frm_row'>  
        <label>Description</label>  
        <textarea id="descF" rows='3' cols='53' name="desc"></textarea>  
    </div>  
    <div class='frm_row'>  
        <label>Image</label>  
        <input id="imageF" type="file" name="uploadedimage">  
        <input type="hidden" name=MAX_FILE_SIZE" value='50000000'/>  
        </input> <br />  
    </div>  
    <div class='frm_row'>  
        <label>Session Media</label>  
        <input type='radio' id="mediaF" name="media" />  
        Upload: <input type='file' name="fileupload">  
        </input> <br />  
        <input type='radio' id="mediaF" name="media" />  
            Enter media URL:  
            <input type='text' size='75' name="mediaFile"/>  
        </input>  
    </div>                  
    <div class='frm_row'>  
        <input type="submit" value="Save Session"/>                     
        <div class='btn' type="submit" style='float: left;'>  
        <a href='#' id='btn_save_session'><span>Save Session</span></a>  
        <div class='kill_clear'></div>  
    </div>  
 </form>  

I know I can do this using multiple forms, but I would like to avoid that and enjoy having just a single 'Save' button. 我知道我可以使用多种形式来做到这一点,但我想避免这种情况,只享受一个“保存”按钮。

Any suggestions? 有什么建议么?

i don't understand the problem, the info will be in the $_POST array and the files in the $_FILES array. 我不明白问题所在,信息将在$ _POST数组中,文件在$ _FILES数组中。 however, you are missing a double quote in MAX_FILE_SIZE, i tested the following code, and it works :D 但是,您在MAX_FILE_SIZE中缺少双引号,我测试了以下代码,并且可以使用:D

<?php
print_r($_POST);
print_r($_FILES);
?>
  <form class='form' name="frm_new_session" method="POST" enctype="multipart/form-data">  
    <div class='frm_row'>  
        <label>Title</label>  
        <input id="titleF" type='text' name="title" size='50' />  
        <input type="hidden" name="_chkuser" value="1"/>  
    </div>  
    <div class='frm_row'>  
        <label>Description</label>  
        <textarea id="descF" rows='3' cols='53' name="desc"></textarea>  
    </div>  
    <div class='frm_row'>  
        <label>Image</label>  
        <input id="imageF" type="file" name="uploadedimage">  
        <input type="hidden" name="MAX_FILE_SIZE" value='50000000'/>  
        </input> <br />  
    </div>  
    <div class='frm_row'>  
        <label>Session Media</label>  
        <input type='radio' id="mediaF" name="media" />  
        Upload: <input type='file' name="fileupload">  
        </input> <br />  
        <input type='radio' id="mediaF" name="media" />  
            Enter media URL:  
            <input type='text' size='75' name="mediaFile"/>  
        </input>  
    </div>                  
    <div class='frm_row'>  
        <input type="submit" value="Save Session"/>                     
        <div class='btn' type="submit" style='float: left;'>  
        <a href='#' id='btn_save_session'><span>Save Session</span></a>  
        <div class='kill_clear'></div>  
    </div>  
 </form>  
<form action="/add-news.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<input type="text" name="title" />
<input type="file" name="image" />
<textarea rows="40" cols="50" name="content"></textarea>
</form>

Try adding hidden field MAX_FILE_SIZE where value is max size of files in bytes. 尝试添加隐藏字段MAX_FILE_SIZE,其中value是文件的最大大小(以字节为单位)。 It works for me. 这个对我有用。

What you mean by: "It can't do both", what are the indications? 您的意思是:“两者不能兼而有之”,这说明什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM