1
下面是我用來上傳不同文件的腳本。我發現的所有解決方案只處理多個圖像上傳。我完全難以找到解決方案。有人能告訴我,我應該怎麼做,以同樣的形式上傳不同的文件?由於在codeigniter中上傳不同文件類型的問題
function do_upload()
{
$config['upload_path'] = './uploads/nav';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$this->load->library('upload', $config);
if (! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
return $error;
}
else
{
$soundfig['upload_path'] = './uploads/nav';
$soundfig['allowed_types'] = 'mp3|wav';
$this->load->library('upload', $soundfig);
if (! $this->upload->do_upload('soundfile'))
{
$error = array('error' => $this->upload->display_errors());
return $error;
}
else
{
$data = $this->upload->data('userfile');
$sound = $this->upload->data('soundfile');
$full_path = 'uploads/nav/' . $data['file_name'];
$sound_path = 'uploads/nav/' . $sound['file_name'];
if($this->input->post('active') == '1'){
$active = '1';
}else{
$active = '0';
}
$spam = array(
'image_url' => $full_path,
'sound' => $sound_path,
'active' => $active,
'url' => $this->input->post('url')
);
$id = $this->input->post('id');
$this->db->where('id', $id);
$this->db->update('NavItemData', $spam);
return true;
}
}
}
這裏是我的形式:
<?php echo form_open_multipart('upload/do_upload');?>
<?php if(isset($buttons)) : foreach($buttons as $row) : ?>
<h2><?php echo $row->name; ?></h2>
<input type="file" name="userfile" size="20" /><br />
<input type="file" name="soundfile" size="20" />
<input type="hidden" name="oldfile" value="<?php echo $row->image_url; ?>" />
<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
<br /><br />
<label>Url: </label><input type="text" name="url" value="<?php echo $row->url; ?>" /><br />
<input type="checkbox" name="active" value="1" <?php if($row->active == '1') { echo 'checked'; } ?> /><br /><br />
<input type="submit" value="submit" />
</form>
<?php endforeach; ?>
<?php endif; ?>
我想保持驗證的地方,因爲用戶往往是白癡!有沒有辦法一次使用兩個不同的配置?歡呼雖然:) – Drew 2010-05-11 16:49:35