|
本帖最后由 风中静草 于 2013-1-29 10:41 编辑
控制類
PHP复制代码
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[0]->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');
}
复制代码
模板類
PHP复制代码
function article_update($id,$array)
{
$this->db->where('id',$id);
$this->db->update('article',$array);
}
复制代码
頁面
HTML复制代码
<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[0]->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[0]->channel_id;?>"/> </td>
</tr>
<tr>
<td>
<?php echo lang('article_title');?>:
</td>
<td><input name="title" type="text" value="<?php echo $article_list[0]->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[0]->description;?>" /> </td>
</tr>
<!--
<tr>
<td>
<?php echo lang('article_litpic');?>:
</td>
<td><input name="lit_pic" type="file" value="<?php echo $article_list[0]->lit_pic;?>"/></td>
</tr>
-->
<tr>
<td>
<?php echo lang('article_content');?>:
</td>
<td><textarea name="body_text" type="text"><?php echo $article_list[0]->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[0]->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的話,直接就這樣了
求幫忙解決,謝謝
|
|