【发布时间】:2012-03-07 23:50:41
【问题描述】:
当然,我的意思是我做错了什么。我之前发布了一个与此类似的问题并得到了一些答案。那么基于这些答案(我现在没有使用CI的课程)我遇到了一个新问题。任何帮助将不胜感激。
PHP
public function do_upload () {
$scopeId = $this->input->get('id');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|pdf';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
echo 'error'; <----- This is what is showing up
// uploading failed. $error will holds the errors.
} else {
$data = array('upload_data' => $this->upload->data());
// uploading successfull, now do your further actions
redirect(site_url('discovery/scopeDetails?scID='.$scopeId.''));
}
echo $error;
}
HTML 表单
<div id="upload">
<?=form_open_multipart('discovery/do_upload');?>
<input name="userfile" size="40" type="file" />
<input type="submit" value="Upload" />
</div>
对于表单,我通常只会使用直接的 HTML,但我尝试完全按照 http://codeigniter.com/user_guide/libraries/file_uploading.html 告诉我的去做。
【问题讨论】:
-
$error 包含什么?我会先检查一下。然后确保你的上传目录有写权限。
-
第二部分该怎么做?
-
你有上传配置文件吗?在某个地方指定您的上传目录?像这样: $config['upload_dir'] = '/home/somesite/www/media/uploads/';然后检查 ftp 或 repo 中的该目录并确保它已应用 chmod 777。右键单击文件夹上的属性
标签: php forms codeigniter upload multipart