phpcms前端頁面上傳文件

今天多虧網友指點,才弄懂了怎麼在前臺上傳文件,記錄下來跟你們分享一下php

PHPCMS其實有一個叫作附件的模塊,上傳用的就是這個東西,如今咱們來看一下對應的文件:phpcms\modules\attachment\attachments.php就是這個文件,大概在29行上(我用的PHPCMS版本號是Phpcms V9.5.8 Release 20140929)有下面一個方法:html

public function upload() {
		$grouplist = getcache('grouplist','member');   //獲取緩存中身份分組的列表
		if($this->isadmin==0 && !$grouplist[$this->groupid]['allowattachment']) return false;   //判斷是否容許上傳附件
		pc_base::load_sys_class('attachment','',0);   //加載attachment類
		$module = trim($_GET['module']);  //經過get方式獲取模型
		$catid = intval($_GET['catid']);  //經過get方式獲取catid
		$siteid = $this->get_siteid();   //獲取站點ID
		$site_setting = get_site_setting($siteid);   //獲取站點配置信息,這個函數在此模塊中的公共函數global.func.php中能夠找到
		$site_allowext = $site_setting['upload_allowext'];	//獲取到容許的上傳文件類型	
		$attachment = new attachment($module,$catid,$siteid);   //實例化attachment類,就是上面剛剛提到的加載進來的類
		$attachment->set_userid($this->userid);  //調用attachment類的set_userid函數,肯定是哪一個用戶上傳的。
		$a = $attachment->upload('upload',$site_allowext);  //上傳文件,具體的函數請查看attachment類。
		if($a){     //下面這些就是上傳成功後的一些路徑和文件名什麼的了~
			$filepath = $attachment->uploadedfiles[0]['filepath'];
			$fn = intval($_GET['CKEditorFuncNum']);
			$this->upload_json($a[0],$filepath,$attachment->uploadedfiles[0]['filename']);
			$attachment->mkhtml($fn,$this->upload_url.$filepath,'');
		}
	}

以上應該解釋的比較詳細了,不懂的話能夠本身看一下對應的文件,好了如今咱們來看前端:前端

<form method="post" enctype="multipart/form-data" action="/index.php?m=attachment&c=attachments&a=upload" id="uploadload" target="iframelogo">
        <input type="file" class="uploadtxt" name="upload" /><input type="submit" value="dianji" />
</form>

這個就是上傳用的~注意調用的action的路徑就行了~再就是這裏的<input type=file name="upload">的name屬性必須爲upload不然沒法上傳成功,由於在attachment類中定死了上傳的name屬性,因此這裏只能用這個了~json

相關文章
相關標籤/搜索