我希望将我的数据从Excel存储到数据库。我是ThinkPHP的新手,所以我挣扎了3天多。
上传正在运行,但数据未更新到数据库中。错误未在页面中显示。我不知道,编码是正确还是错误。 Html编码
<form name="importForm" id="importForm" action="__APP__" method="POST">
<input type="file" name="file" /><br />
<input type="submit" name="submit" onclick="import_csv_payment();" value="Submit" />
</form>
脚本
function import_csv_payment()
{
var query = $("#importForm").serialize();
var url= ROOT+"?"+VAR_MODULE+"="+MODULE_NAME+"&"+VAR_ACTION+"=import_csv_payment"+"&"+query;
location.href = url;
}
Php Modules
这是我的上传和存储功能
public function import_csv_payment($page = 1)
{
if (!empty($_FILES))
{
import("@.ORG.UploadFile");
$config=array(
'allowExts'=>array('xlsx','xls'),
'savePath'=>'./Public/upload/',
'saveRule'=>'time',
);
$upload = new UploadFile($config);
if (!$upload->upload()) {
$this->error($upload->getErrorMsg());
} else {
$info = $upload->getUploadFileInfo();
}
vendor("PHPExcel.PHPExcel");
$file_name=$info[0]['savepath'].$info[0]['savename'];
$handle = fopen($file_name, “r”);
$c = 0;
while(($filesop = fgetcsv($handle, 1000, “,”)) !== false)
{
$id = $filesop[0];
$deal_name = $filesop[1];
$ngo = $filesop[2];
$project = $filesop[3];
$update = $GLOBALS['db']->query("update ".DB_PREFIX."payment_notice set deal_name = '".$deal_name."',ngo='".$ngo."',project='".$project."' where id = '".$id."' ");
$c++;
}
$this->success('Import success!');
} else {
$this->error("Please choose to upload the file");
}
}