我是codeigniter的新手..请帮助我在codeigniter中上传图像。首先我需要在“codeigniter/userimage/”内创建一个子文件夹,用户ID作为文件夹名称。我做到了。这是我的控制器功能
function update(){
$uppath="/var/www/html/codeigniter/userimage/";
$sess_id= $this->session->userdata('userid');
$folder=$uppath.$sess_id;
if(!is_dir($folder))
mkdir ($folder,777);
if($x>0){
$config['upload_path']='./userimage/'.$folder.'/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '9000';
$config['max_width'] = '1024';
$config['max_height'] = '1000';
echo 'haii';
$this->load->library('upload');
$this->upload->initialize($config);
echo 'heloooo';
if (!$this->upload->do_upload('picfile')) {
print_r( $this->upload->display_error() );die;
}
else {
$image=$this->upload->do_upload('picfile');
// echo 'uploaded';
echo $image;
}
}
}
我正在从视图'profileinfo'调用我在模型'home'中写入的方法更新。
我的视图 profileinfo 是:
`<?php
$fn='';
$ln='';
$un='';
$em='';
$b='';
$gr='';
foreach ($query as $row){
$fn=$row->firstname;
$ln=$row->lastname;
$un=$row->username;
$em=$row->email;
$b=$row->bday;
$gr=$row->gender;
}
?>
<html>
<head></head>
<body>
<h1><u>My Profile Details</u></h1>
<br><br><div id="viewdiv" align="center">
<div align="right" style="font-weight: bold;font-size: 20px;">
<a href="home">Back</a></div>
<?php echo form_open_multipart('home/update');?>
<br>
<table border="0" align="center">
<tr class='spacerow'>
<td>
<h2> Name:</h2>
</td>
<td><?php echo"<input type='text' name='first' value='$fn'>";?>
<?php echo"<input type='text' name='last' value='$ln'>";?></td>
</tr>
<tr class='spacerow'>
<td>
<h2> User Name:</h2>
</td>
<td>
<?php echo"<input type='text' name='uname' value='$un'>";?>
</td>
</tr>
<tr class='spacerow'>
<td>
<h2> Date of birth:</h2>
</td>
<td>
<?php echo"<input type='text' name='dobb' id='datepicker' value='$b'>";?>
</td>
</tr>
<tr class='spacerow'>
<td>
<h2> Gender: </h2>
</td>
<?php
if($gr=="male"){
?>
<td>
<?php echo"<h3>Male:<input type='radio' name='gen' value='male' checked>";?>
<?php echo"Female:<input type='radio' name='gen' value='female' ></h3>";?>
</td>
<?php
}
else{
?>
<td>
<?php echo"<h3>Male:<input type='radio' name='gen' value='male'>";?>
<?php echo"Female:<input type='radio' name='gen' value='female' checked></h3>";?>
</td>
<?php
}
?>
</tr>
<tr class='spacerow'>
<td>
<h2> Email:</h2>
</td>
<td>
<?php echo"<input type='text' name='mail' value='$em'>";?>
</td>
</tr>
<tr class='spacerow'>
<td>
<h2> Profile Picture:</h2>
</td>
<td>
<input type="file" name="picfile">
<p>if you want to change your profile picture,browse here..</p>
</td>
</tr>
<tr>
<td><br>
<center> <input type="submit" name="update" value="update"></center>
</td>
<td>
</td>
</tr>
</table>
</div>
</body>
` 子文件夹“$folder”正在用户图像中创建,我想将上传的图像存储到该子文件夹中。我的问题是图像没有上传。你可以看到我在加载上传库之前和之后放置了两个 echo 语句。但我只得到输出“haii”..我不知道是什么问题..请任何人帮助我..谢谢..