我是新codeigniter ..請幫助我上傳codeigniter.first圖像我需要創建一個子文件夾「codeigniter/userimage /」與用戶ID作爲文件夾名稱。我做that.this是我的控制器功能圖像上傳到codeigniter子文件夾
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」模型「家」裏寫的方法更新。
我的看法是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>
` 子文件夾「$文件夾」在裏面userimage創造,我想存儲上傳的圖片成子folder.my問題是圖像不上傳。你可以看到我在加載上傳庫之前和之後放置了兩個echo語句。但我發現只有輸出「haii」 ..我不明白什麼是problem..please人幫助我..感謝任何想法..
那麼到底是什麼由do_upload函數返回?什麼是錯誤信息? – Technoh
您需要使用chmod()賦予文件夾的777權限。 – Prasannjit
@Technoh:沒有錯誤消息顯示..當我點擊按鈕後瀏覽圖像的URL顯示頁面正在移動到控制器中指定的方法..但圖像不上傳...這是我的問題.. – user007