Debugging 将文本/word文件上载到cakephp中,然后实时查看
我想能够上传到数据库中的文件,然后有一个查看链接,这样我就可以看到这个文件以及。基本上,所有保存的文件都应该显示在索引页面中,如果我单击查看按钮,文件的内容应该显示在查看页面中。我正在使用这些代码,以下是我的控制器部分:Debugging 将文本/word文件上载到cakephp中,然后实时查看,debugging,cakephp,Debugging,Cakephp,我想能够上传到数据库中的文件,然后有一个查看链接,这样我就可以看到这个文件以及。基本上,所有保存的文件都应该显示在索引页面中,如果我单击查看按钮,文件的内容应该显示在查看页面中。我正在使用这些代码,以下是我的控制器部分: public function add(){ if ($this->request->is('post')){ $this->Doc->create(); $filename = $this-&g
public function add(){
if ($this->request->is('post')){
$this->Doc->create();
$filename = $this->request->data['Doc']['docname']['name'];
$this->request->data['Doc']['docname'] = $filename;
if ($this->Doc->save($this->request->data)){
$this->Session->setFlash('Message : ' . $filename);
$this->redirect(array('action' => 'index'));
}else{
$this->Session->setFlash(__('The Doc could not be saved. Please, try again'));
$this->redirect(array('action' => 'add'));
}
}
}
以下是我在app/view下的添加功能:
<div class="doc form">
<?php echo $this->Form->create('Doc', array('type' => 'file')); ?>
<fieldset>
<table align="left">
<tr>
<td>
<?php echo $this->Form->input('docname', array('type' => 'file'));?>
</td>
</tr>
</table>
</fieldset>
<div align="center" style="padding: 20px">
<?php echo $this->Html->link('Cancel',array('controller' => 'docs', 'action' => 'index'), array('class' => 'btn btn-primary')); ?>
<?php echo $this->Form->button('Submit',array('type'=>'upload','class'=>'btn btn-primary')); ?>
<?php echo $this->Form->end(); ?>
}您能告诉我使用的cakephp版本、使用的表格/db以及文档的型号吗?谢谢您的快速回复。我刚刚编辑了我的问题,并把你问的细节放进去。这个插件可能会帮助你:谢谢,我让它工作了。
class Doc extends AppModel {
//The Associations below have been created with all possible keys, those that are not needed can be removed
public $belongsTo = array(
'Grant' => array(
'className' => 'Grant',
'foreignKey' => 'grant_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);