本文整理汇总了PHP中Controller::actionUpload方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::actionUpload方法的具体用法?PHP Controller::actionUpload怎么用?PHP Controller::actionUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller::actionUpload方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Tax::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Tax();
}
$model->taxid = (int) $data[0];
$model->taxcode = $data[1];
$model->taxvalue = $data[2];
$model->description = $data[3];
$model->recordstatus = (int) $data[4];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例2: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Company::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Company();
}
$model->companyid = (int) $data[0];
$model->companyname = $data[1];
$model->address = $data[2];
$city = City::model()->findbyattributes(array('cityname' => $data[3]));
if ($city !== null) {
$model->cityid = $city->cityid;
}
$model->zipcode = $data[4];
$model->taxno = $data[5];
$currency = Currency::model()->findbyattributes(array('currencyname' => $data[6]));
if ($currency !== null) {
$model->currencyid = $currency->currencyid;
}
$model->recordstatus = (int) $data[7];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例3: actionUpload
public function actionUpload()
{
parent::actionUpload();
Yii::import("ext.EAjaxUpload.qqFileUploader");
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$allowedExtensions = array("csv");
$sizeLimit = (int) Yii::app()->params['sizeLimit'];
// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder, true);
$row = 0;
if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Absrule::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Absrule();
}
$model->absruleid = (int) $data[0];
$model->absscheduleid = (int) $data[1];
$model->difftimein = $data[2];
$model->difftimeout = $data[3];
$model->absstatusid = (int) $data[4];
$model->recordstatus = 1;
try {
if (!$model->save()) {
$errormessage = $model->getErrors();
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
}
}
} catch (Exception $e) {
$errormessage = $e->getMessage();
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
}
}
}
$row++;
}
fclose($handle);
}
$result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;
}
示例4: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$empid = Employee::model()->findbyattributes(array('oldnik' => $data[0]));
$model = new Employeeschedule();
if ($empid != null) {
$model = Employeeschedule::model()->findByattributes(array('employeeid' => $empid->employeeid, 'month' => $data[2], 'year' => $data[3]));
if ($model == null) {
$model = new Employeeschedule();
}
$model->employeeid = $empid->employeeid;
$model->month = $data[2];
$model->year = $data[3];
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[4]));
if ($d != null) {
$model->d1 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[5]));
if ($d != null) {
$model->d2 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[6]));
if ($d != null) {
$model->d3 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[7]));
if ($d != null) {
$model->d4 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[8]));
if ($d != null) {
$model->d5 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[9]));
if ($d != null) {
$model->d6 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[10]));
if ($d != null) {
$model->d7 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[11]));
if ($d != null) {
$model->d8 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[12]));
if ($d != null) {
$model->d9 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[13]));
if ($d != null) {
$model->d10 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[14]));
if ($d != null) {
$model->d11 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[15]));
if ($d != null) {
$model->d12 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[16]));
if ($d != null) {
$model->d13 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[17]));
if ($d != null) {
$model->d14 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[18]));
if ($d != null) {
$model->d15 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[19]));
if ($d != null) {
$model->d16 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[20]));
if ($d != null) {
$model->d17 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[21]));
if ($d != null) {
$model->d18 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[22]));
if ($d != null) {
$model->d19 = $d->absscheduleid;
}
$d = Absschedule::model()->findbyattributes(array('absschedulename' => $data[23]));
if ($d != null) {
$model->d20 = $d->absscheduleid;
//.........这里部分代码省略.........
示例5: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Menuauth::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Menuauth();
}
$model->menuauthid = (int) $data[0];
$menuname = Menuaccess::model()->findbyattributes(array('menuname' => $data[1]));
if ($menuname !== null) {
$model->menuaccessid = $menuname->menuaccessid;
}
$model->menuobject = $data[2];
$model->recordstatus = (int) $data[3];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
}
}
}
示例6: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = $this->loadModel((int) $data[0]);
if ($model === null) {
$model = new Addressbook();
}
$model->fullname = $data[1];
$model->iscustomer = (int) $data[2];
$model->isemployee = (int) $data[3];
$model->isapplicant = (int) $data[4];
$model->isvendor = (int) $data[5];
$model->isinsurance = (int) $data[6];
$model->isbank = (int) $data[7];
$model->ishospital = (int) $data[8];
$model->iscatering = (int) $data[9];
$model->recordstatus = (int) $data[10];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例7: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$allowedExtensions = array("csv");
$sizeLimit = (int) Yii::app()->params['sizeLimit'];
// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder, true);
$row = 0;
if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Productdetail::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Productdetail();
}
$model->productdetailid = (int) $data[0];
$model->productid = $data[1];
$model->baseuom = $data[2];
$model->materialgroupid = (int) $data[3];
$model->oldmatno = $data[4];
$model->divisionid = (int) $data[5];
$model->grossweight = $data[6];
$model->weightunit = $data[7];
$model->netweight = $data[8];
$model->volume = $data[9];
$model->volumeunit = (int) $data[10];
$model->sizedimension = $data[11];
$model->materialpackage = (int) $data[12];
$model->recordstatus = (int) $data[13];
try {
if (!$model->save()) {
$errormessage = $model->getErrors();
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
}
}
} catch (Exception $e) {
$errormessage = $e->getMessage();
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
}
}
}
$row++;
}
fclose($handle);
}
$result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;
}
示例8: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Groupmenu::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Groupmenu();
}
$model->groupmenuid = (int) $data[0];
$groupaccess = Groupaccess::model()->findbyattributes(array('groupname' => $data[1]));
if ($groupaccess !== null) {
$model->groupaccessid = $groupaccess->groupaccessid;
}
$menuaccess = Menuaccess::model()->findbyattributes(array('menuname' => $data[2]));
if ($menuaccess !== null) {
$model->menuaccessid = $menuaccess->menuaccessid;
}
$model->isread = (int) $data[3];
$model->iswrite = (int) $data[4];
$model->ispost = (int) $data[5];
$model->isreject = (int) $data[6];
$model->isupload = (int) $data[7];
$model->isdownload = (int) $data[8];
$model->recordstatus = (int) $data[9];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例9: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
if ($data[0] != '') {
$model = new Genjournal();
$model->journaldate = $data[0];
$model->postdate = $data[0];
$model->referenceno = $data[1];
$model->recordstatus = Wfgroup::model()->findstatusbyuser('insgenjournal');
$model->save();
$oldid = $model->genjournalid;
}
if ($oldid != 0) {
$detail = new Journaldetail();
$detail->genjournalid = $oldid;
$account = Account::model()->findbysql("select accountid from account where upper(accountcode) = '" . $data[2] . "'");
if ($account != null) {
$detail->accountid = $account->accountid;
}
if ($data[3] != '') {
$detail->debit = $data[3];
$detail->credit = 0;
}
if ($data[4] != '') {
$detail->debit = 0;
$detail->credit = $data[4];
}
$currency = Currency::model()->findbysql("select currencyid from currency where upper(currencyname) = '" . $data[5] . "'");
if ($currency != null) {
$detail->currencyid = $currency->currencyid;
}
$detail->detailnote = $data[1];
if (!$detail->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
}
}
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例10: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$allowedExtensions = array("csv");
$sizeLimit = (int) Yii::app()->params['sizeLimit'];
// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder, true);
$row = 0;
if (($handle = fopen($folder . $uploader->file->getName(), "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Groupmenuauth::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Groupmenuauth();
}
$model->groupmenuid = (int) $data[0];
$model->groupaccessid = (int) $data[1];
$model->menuaccessid = (int) $data[2];
$model->isread = (int) $data[3];
$model->iswrite = (int) $data[4];
$model->ispost = (int) $data[5];
$model->isreject = (int) $data[6];
$model->isupload = (int) $data[7];
$model->isdownload = (int) $data[8];
$model->recordstatus = (int) $data[9];
try {
if (!$model->save()) {
$errormessage = $model->getErrors();
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
}
}
} catch (Exception $e) {
$errormessage = $e->getMessage();
if (Yii::app()->request->isAjaxRequest) {
echo CJSON::encode(array('status' => 'failure', 'div' => $errormessage));
}
}
}
$row++;
}
fclose($handle);
}
$result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
echo $result;
}
示例11: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Account::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Account();
}
$model->accountid = (int) $data[0];
$model->accountcode = $data[1];
$model->accountname = $data[2];
if ($data[3] != '') {
$model->parentaccountid = (int) $data[3];
} else {
$model->parentaccountid = null;
}
if ($data[4] != '') {
$accounttype = Accounttype::model()->findbysql("select * from accounttype where upper(accounttypename) = upper('" . $data[4] . "')");
if ($accounttype != null) {
$model->accounttypeid = $accounttype->accounttypeid;
} else {
$model->accounttypeid = null;
}
} else {
$model->accounttypeid = null;
}
if ($data[5] != '') {
$currency = Currency::model()->findbysql("select * from currency where upper(currencyname) = upper('" . $data[5] . "')");
if ($currency != null) {
$model->currencyid = $currency->currencyid;
} else {
$model->currencyid = null;
}
} else {
$model->currencyid = null;
}
$model->recordstatus = $data[6];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例12: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = $this->loadModel((int) $data[0]);
if ($model === null) {
$model = new Useraccess();
}
$model->useraccessid = $data[0];
$model->username = $data[1];
$model->realname = $data[2];
$model->email = $data[3];
$model->phoneno = $data[4];
$model->salt = $model->generatesalt();
$model->password = $model->hashpassword('demo', $model->salt);
$language = Language::model()->findbyattributes(array('languagename' => $data[5]));
if ($language !== null) {
$model->languageid = $language->languageid;
}
$model->recordstatus = (int) $data[6];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例13: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Jobs::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Jobs();
}
$model->jobsid = (int) $data[0];
$structure = Orgstructure::model()->findbyattributes(array('structurename' => $data[1]));
if ($structure !== null) {
$model->orgstructureid = $structure->orgstructureid;
}
$position = Orgstructure::model()->findbyattributes(array('positionname' => $data[2]));
if ($position !== null) {
$model->positionid = $structure->positionid;
}
$model->jobdesc = $data[3];
$model->qualification = $data[4];
$model->recordstatus = (int) $data[5];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}
示例14: actionUpload
public function actionUpload()
{
parent::actionUpload();
$folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
// folder for uploaded files
$file = $folder . basename($_FILES['uploadfile']['name']);
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row > 0) {
$model = Employeetype::model()->findByPk((int) $data[0]);
if ($model === null) {
$model = new Employeetype();
}
$model->employeetypeid = (int) $data[0];
$model->employeetypename = $data[1];
$snro = Snro::model()->findbyattributes(array('description' => $data[2]));
if ($snro != null) {
$model->snroid = $snro->snroid;
}
$snro = Snro::model()->findbyattributes(array('description' => $data[3]));
if ($snro != null) {
$model->sicksnroid = $snro->snroid;
}
$snro = Absstatus::model()->findbyattributes(array('shortstat' => $data[4]));
if ($snro != null) {
$model->sickstatusid = $snro->absstatusid;
}
$model->recordstatus = (int) $data[5];
try {
if (!$model->save()) {
$this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
}
} catch (Exception $e) {
$this->messages = $this->messages . $e->getMessage();
}
}
$row++;
}
} else {
$this->messages = $this->messages . ' memory or harddisk full';
}
fclose($handle);
} else {
$this->messages = $this->messages . ' check your directory permission';
}
if ($this->messages == '') {
$this->messages = 'success';
}
echo $this->messages;
}