codeigniter的上傳類的問題,麻煩幫忙看看
本帖最后由 风中静草 于 2013-1-29 10:41 编辑控制類
function article_update()
{
$this->load->model('article_model');
var_dump($_FILES['doc_file']);
echo "<br/>";
if($_FILES['doc_file'])
{
$file_root = getcwd();
$web_root = str_replace("\CMS","\\","$file_root");
$user_id = $this->session->userdata('userid');
$school_arr = $this->article_model->article_school_select($user_id);
$school_webapppath = $school_arr->webapp_path;
$school_root = $web_root."school\\".$school_webapppath;
$file_name = time();
$config['upload_path'] = "D:\a";
$config['allowed_types'] = "jpg|pdf";
$config['file_name'] = $file_name;
$config['max_size'] = "20000000";
$arr = array('channel_id'=>$_POST['channel_id'],
'title'=>$_POST['title'],
'description'=>$_POST['description'],
#'lit_pic'=>$_POST['lit_pic'],
'body_text'=>$_POST['body_text'],
'doc_file'=>"./".$school_webapppath."/upload/article/".$config['file_name'].".pdf",
'published_date'=>date("Y-m-d H:i:s",time()),
'article_type'=>"1");
$this->article_model->article_update($this->uri->segment(3),$arr);
//上傳PDF開始
$this->load->library('upload',$config);
$data=array('upload_data'=>$this->upload->data());
var_dump($data);
if(! $this->upload->do_upload('DocFile'))
{
$error=array('error'=>$this->upload->display_errors());
var_dump($error);
break;
}
//上傳PDF結束
}
else
{
$arr = array('channel_id'=>$_POST['channel_id'],
'title'=>$_POST['title'],
'description'=>$_POST['description'],
#'lit_pic'=>$_POST['lit_pic'],
'body_text'=>$_POST['body_text'],
'doc_file'=>"",
'published_date'=>date("Y-m-d H:i:s",time()),
'article_type'=>"0");
$this->article_model->article_update($this->uri->segment(3),$arr);
}
redirect('article');
}
模板類
function article_update($id,$array)
{
$this->db->where('id',$id);
$this->db->update('article',$array);
}
頁面
<script type="text/javascript">
function showhide(show, hide)
{
document.getElementById(show).style.display='block';
document.getElementById(hide).style.display='none';
}
</script>
<h2><?php echo lang('article_edit');?></h2>
<div>
<form name="article_edit" method="post" action="../article_update/<?php echo $article_list->id; ?>" enctype="multipart/form-data">
<table class="table table-bordered table-striped">
<table class="table table-bordered table-striped">
<tr>
<td width="250"><?php echo lang('article_style');?>:</td>
<td>
<input type="radio" checked="checked" value="image" name="singleformat">
<?php echo lang('article_pdf_format');?>
<input type="radio" value="html" name="singleformat">
<?php echo lang('article_web_format');?>
</td>
</tr>
<tr>
<td>
<?php echo lang('article_format');?>:
</td>
<td><input name="channel_id" type="text" value="<?php echo $article_list->channel_id;?>"/></td>
</tr>
<tr>
<td>
<?php echo lang('article_title');?>:
</td>
<td><input name="title" type="text" value="<?php echo $article_list->title;?>" /></td>
</tr>
</table>
<table id="singlehtml" style="display:none"class="table table-bordered table-striped">
<tr>
<td width="250">
<?php echo lang('article_description');?>:
</td>
<td><input name="description" type="text" value="<?php echo $article_list->description;?>" /></td>
</tr>
<!--
<tr>
<td>
<?php echo lang('article_litpic');?>:
</td>
<td><input name="lit_pic" type="file" value="<?php echo $article_list->lit_pic;?>"/></td>
</tr>
-->
<tr>
<td>
<?php echo lang('article_content');?>:
</td>
<td><textareaname="body_text" type="text"><?php echo $article_list->body_text;?></textarea></td>
</tr>
</table>
<table id="singleimage" style="display:block" class="table table-bordered table-striped">
<tr>
<td width="250">
<?php echo lang('article_pdf');?>:
</td>
<td><input name="doc_file" type="file" value="<?php echo $article_list->doc_file;?>" /></td>
</tr>
</table>
<tr>
<td>
<input name="sub" type="submit" value="<?php echo lang('article_upgrade');?>">
</td>
</tr>
</table>
</form>
</div>
如果上傳的是JPG的話,
var_dump($_FILES['doc_file']);
的結果是
array(5) {["name"]=>string(14) "1359351719.jpg"["type"]=>string(10) "image/jpeg"["tmp_name"]=>string(27) "C:\Windows\Temp\php9CD3.tmp"["error"]=>int(0)["size"]=>int(845941)}
但是上傳報錯
array(1) {["error"]=>string(30) "upload_no_file_selected
"}
如果上傳的是PDF的話,直接就這樣了
求幫忙解決,謝謝
upload_no_file_selected 没有选择要上传的文件
JPG上传的时候正常,而pdf上传的时候有问题,那么就只有一个,上传时请求的头信息,具体请看application/config/mimes.php文件 sdink 发表于 2013-1-29 13:37 static/image/common/back.gif
upload_no_file_selected 没有选择要上传的文件
JPG上传的时候正常,而pdf上传的时候有问题,那么就只 ...
但是連var_dump($_FILES['doc_file'])都打印不出來信息啊,
上傳圖片都是報錯的
array(1) {
["error"]=>string(30) "upload_no_file_selected
"}
页:
[1]