我是codeignitor的初学者。我想通过post方法发布图片。正在发布所有数据,但图像未在控制器中发布。
这是我的观看代码。
<form action="<?php echo site_url('adminpanel/add_event');?>" method="post" name="addform" enctype="multipart/form-data">
<fieldset>
<p>
<label style="width:20%;float:left;">Event Title<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_title" id="event_title" placeholder="Event Title" value="<?php if(isset($teenzstore_edit_data['product_name'])) echo $teenzstore_edit_data['product_name'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Select Age<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<select name="age" id="age" class="form-control" class="form-control" onChange="return get_product_filter('<?php echo base_url();?>',this.value);">
<option value="0">Select Age</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</select>
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Image</label>
<label style="width:1%;float:left;">:</label>
<input type="file" name="event_image" id="event_image" onchange="checkExtension(this.value)" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Date<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_date" id="event_date" placeholder="Event Date" value="<?php if(isset($teenzstore_edit_data['product_points'])) echo $teenzstore_edit_data['product_points'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Time<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_time" id="event_time" placeholder="Event Time" value="<?php if(isset($teenzstore_edit_data['product_points'])) echo $teenzstore_edit_data['product_points'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Venue <span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<label style="width:20%;float:left;">
<textarea cols="80" id="event_venue" style="width:77% !important;" name="event_venue" rows="10">
<?php if(isset($restaurant_edit_data[ 'rest_description'])) echo $restaurant_edit_data[ 'rest_description'];?>
</textarea>
</p>
<script type="text/javascript">
CKEDITOR.replace('event_venue', {
width: "630",
});
</script>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Description <span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<label style="width:20%;float:left;">
<textarea cols="80" id="event_desc" style="width:77% !important;" name="event_desc" rows="10">
<?php if(isset($restaurant_edit_data[ 'rest_description'])) echo $restaurant_edit_data[ 'rest_description'];?>
</textarea>
</p>
<script type="text/javascript">
CKEDITOR.replace('event_desc', {
width: "630",
});
</script>
</fieldset>
<div class="clear"></div>
<p>
<label style="width:20%;float:left;"> </label>
<label style="width:1%;float:left;"> </label>
<input class="button" type="submit" name="submit" value="Submit" />
<input class="button" type="button" value="Cancel" name="cancel" onclick="javascript:history.go(-1);" />
</p>
</form>
答案 0 :(得分:0)
我无法找到问题,因为在我的电脑中一切正常,但可以解释方法调试:
1)从代码中删除任何与问题无关的片段:
我用这个创建了index.html
:
<html>
<head>
<meta lang="en">
</head>
<body>
<form action="test.php" method="post" name="addform" enctype="multipart/form-data">
<fieldset>
<hr>
<p>
<label style="width:20%;float:left;">Event Image</label>
<label style="width:1%;float:left;">:</label>
<input type="file" name="event_image" id="event_image" onchange="checkExtension(this.value)" />
</p>
<p style="clear:both;"></p>
<hr>
</fieldset>
<div class="clear"></div>
<p>
<label style="width:20%;float:left;"> </label>
<label style="width:1%;float:left;"> </label>
<input class="button" type="submit" name="submit" value="Submit" />
<input class="button" type="button" value="Cancel" name="cancel" onclick="javascript:history.go(-1);" />
</p>
</form>
</body>
</html>
接下来,我在同一目录中创建了文件test.php
,内容为:
<?php
var_dump($_POST);
var_dump($_FILES);
在表格中连接文件后,我获得了以下内容:
array(1) { ["submit"]=> string(6) "Submit" } array(1) { ["event_image"]=> array(5) { ["name"]=> string(38) "image.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(14) "/tmp/phpBQAZXv" ["error"]=> int(0) ["size"]=> int(124622) } }
告诉我你的测试结果。可能问题在于处理,而不是形式。
答案 1 :(得分:0)
在您的控制器中使用add_event的名称创建一个函数,因为您要将表单数据发布到此操作。您的代码可能如下所示
class adminpanel extands CI_Controller{
function add_event(){
echo $_FILES['event_image']['name'];
}
}