请考虑以下情况。
查看文件代码
<form id="userProfileForm" action="<?php echo $_SESSION['base_url'];?>home/edit_user" method="post" enctype="multipart/form-data" class="Paragraph-Text">
<label>Name:
<input type="text" name="name">
</label>
<label>Password:
<input type="password" name="password">
</label>
<label for="1" onclick="open_dialog();" class="custom-file-upload font-s-10">
<i class="glyphicon glyphicon-upload"></i> UPLOAD FILE
</label>
<input type="submit">
</form>
脚本
<script>
function open_dialog()
{
$.ajax({
type: "POST",
url: "<?php echo site_url('home/upload_dialog');?>",
data: {count:1},
dataType: "html",
success:
function(html){
$('body').append(html);
$('#child-overlay').animate({opacity: 1}, 400);
}
});
}
</script>
Controller home
function upload_dialog()
{
$this->load->view('home/home-upload-dialog');
}
function upload_area($count)
{
$data['count'] = $count;
$data['accept_file_types']='gif|jpe?g|png|jpg|pdf|cr2|docx|avi|mp4';
$this->load->view('home/upload-area' ,$data);
}
查看home-upload-dialog
<div id="child-overlay-upload">
<div id="popup">
<div class="heading-area">
<p class="heading">UPLOAD FILE</p>
<span id="close"><img src='<?php echo image_url("icons/Cancel-icon.png")?>'></span>
</div>
<div id="popup-contents">
<iframe id="upload-frame" frameborder="0" scrolling="no" height="200" width="100%" src="<?php echo site_url('home/upload_area/' . $_REQUEST['count']);?>"></iframe>
</div>
</div>
</div>
查看upload_area
<input type="hidden" name="file_name" value="someValue">
在这里,如何将数据(来自输入"name","password","file_name"
)通过我的表单操作发布到我的控制器?任何帮助,将不胜感激。谢谢。
PS:请不要问我为什么要这样做。
答案 0 :(得分:1)
首先查看您的HTML,当用户点击提交按钮时,您的家庭控制器中的函数edit_user()
被称为
<form id="userProfileForm" action="<?php echo $_SESSION['base_url'];?>home/edit_user" method="post" enctype="multipart/form-data" class="Paragraph-Text">
因此,在家庭控制器的edit_user()
功能中,您可以执行类似这样的操作
edit_user() {
$username = $_POST['name'];
$password = $_POST['password'];
}
只能让您访问名称和密码。对于您尝试上传的文件,您在html中缺少<input>
,请参阅下文。
<form id="userProfileForm" action="<?php echo $_SESSION['base_url'];?>home/edit_user" method="post" enctype="multipart/form-data" class="Paragraph-Text">
<label>Name:
<input type="text" name="name">
</label>
<label>Password:
<input type="password" name="password">
</label>
<label for="1" class="custom-file-upload font-s-10">
<i class="glyphicon glyphicon-upload"></i> UPLOAD FILE
<input type="file" name="filename">
</label>
<input type="submit">
使用该附加输入标记,您可以更改edit_user()
函数,如此
edit_user() {
$username = $_POST['name'];
$password = $_POST['password'];
$filename = $_FILES['filename']['name'];
}
您可能需要稍微弄清楚使用upload_dialog()
函数获得您正在寻找的内容。这是一些参考文献