doc.php页面 public function add($seq='')
{
$data = array('info' => array(),'doc' =>array());

if(strlen($seq) > 0)
{
$document = Cl::get('Document');
try
{
$document->load($seq);
$data['info'] = array( 'document_code'  => $document['document_code'],
'document_name'  => $document['document_name'],
'fk_document_sign_set_code' => $document['fk_document_sign_set_code'],
'document_use_flag'  => $document['document_use_flag'],
'document_del_flag'  => $document['document_del_flag'],
'document_type' => $document['document_type'],
'doc_uploadfile' => (file_exists(WWWPATH.'/upload/documents/'.$document['document_code'])? '/upload/documents/'.$document['document_code']:'')
);
}d
catch(Exception $e){}
}

$data['doc'] = Cl::get('Document');
$this->_layout("popup");
$this->_view($data);
}上面代码调用下面页面的代码。add.php页面
<tr>
<th>上传文件</th>
<td>
<input type="file" class="file" name="document_file" value="" style="height:27px;"/>
<a href="/hosts/www/upload/documents/{info.document_code}" target="_blank">{info.document_name}点击下载</a><br> </td>
</tr>情况是文件已经保存到了项目的/upload/documents目录下,用文档编号来保存上传文件的名字,因为要上传的文件名字都是文档编号。现在想按照add.php页面的形式下载相关的文件,但点击下载的时候不进行下载,而是将文件的路径写到浏览器上,浏览器上提示404.  貌似是没有找到文件,但文件的路径是对的。 听说要下载需要写header,但我不知道header要写哪里? 请各位指点指点。

解决方案 »

  1.   

    上传是用如下代码实现的
    public function insert()
    {
    $response = array('error' => true);
    /****************************************************************/
    $document_code  = (string) $this->input->post('document_code');
    $document_name  = (string) $this->input->post('document_name');
    $category_type  = (string) $this->input->post('category_type');
    $document_file = @$_FILES['document_file'];
    $document_filename = $_FILES['document_file']['name'];
    /****************************************************************/
    if($this->is_post() == true)
    {

    if(is_uploaded_file($document_file['tmp_name']))
    {
    if(in_array($document_file['type'], array( 'application/msword',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
    'application/vnd.ms-excel',
    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    'text/csv')
    ))
    { $path = '/upload/documents/'.$document_code;
    if(file_exists(PROJECTPATH.'hosts/www'.$path) == TRUE)
    {
    @chmod(PROJECTPATH.'hosts/www'.$path, 0777);
    @unlink(PROJECTPATH.'hosts/www'.$path);
    if(move_uploaded_file($document_file['tmp_name'], PROJECTPATH.'hosts/www'.$path)){}
    }
    else
    {
    if(move_uploaded_file($document_file['tmp_name'], PROJECTPATH.'hosts/www'.$path)){}
    }
    }
    }

    $document = Cl::get('Document');
    $document['document_code']  = $document_code;
    $document['document_name']  = $document_name;
    $document['document_type']  = $category_type;
    try
    {
    $document->insert();
    $response['error']  = false;
    $response['msg'] = '添加成功';
    }
    catch(Exception $e)
    {
    $response['msg'] = $e->getMessage();
    }
    }
    $scripts = array( 'if(opener){opener.location = opener.location.href;}',
    'window.close();',
    );
    $this->msg($response['msg'], '', $scripts);
    }