我想要的是上传的文件名怎么获取? 在如下的download和add方法里? 因为insert方法里可以通过$_FILES['document_file']['name'];获得,但这里在执行保存操作的时候获得,但之前download和add方法是insert方法之前执行的。不知道我的意思有没有表达清楚。控制器段代码
function download($filename,$path,$content_type='application/octet-stream'){

if(strlen($filename) < 0)
{
     如何获取上传的文件名???
}
if(strlen($path) < 0 )
{
$path = WWWPATH.'/upload/documents/这里是上传的文件名';
}

    ob_clean();
    header('Pragma: public');
    header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-store, max-age=0, no-cache, must-revalidate'); // HTTP/1.1
    header('Cache-Control: post-check=0, pre-check=0', false);
    header('Cache-Control: private');
    header('Content-Transfer-Encoding: none'); 
    header('Content-Disposition: attachment; filename='.$filename.'');
    header('Content-Type: '.$content_type.'; name="'.$filename.'"');
    echo file_get_contents($path);
    exit;
}如下方法是 添加和编辑共同使用的方法
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/'.上传的文件名)? '/upload/documents/'.上传的文件名:'')
);
}
catch(Exception $e){}
}

$data['doc'] = Cl::get('Document');
$this->_layout("popup");
$this->_view($data);
}

如下方法是执行保存的方法,即保存相关内容到数据库以及将上传文件保存到指定的项目目录里。
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_filename;
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)){}
}
}
}
如下是view里的代码,添加和编辑是一个页面add.php <tr>
<th>文档名</th>
<td>
<input type="text" class="document_name" name="document_name" size="30" value="{info.document_name}" />
</td>
</tr>
<tr>
<th>上传文件</th>
<td>
<!--{? info.doc_uploadfile}-->
<input type="file" class="file" name="document_file" value="" style="height:27px;"/>
<a class="download">{上传的文件名}点击下载</a><br>
<!--{:}-->
<input type="file" class="file" name="document_file" value="" style="height:27px;"/>
<!--{/}-->
</td>
</tr>如下是JS代码
$('.download').click(function(){
$('form[name=frm_document]').attr('action','/hr/doc/download');
$('form[name=frm_document]').submit();
});