PHP讀取TXT檔案寫入資料庫

2021-06-16 21:23:07 字數 1408 閱讀 2740

php讀取txt檔案寫入資料庫完整**如下(包括檔案型別、大小、欄位為空的判斷,以及事務的處理):

<?php 

$uploadfile="../upload_files/".basename($_files['userfile']['name']);

$message="";

//判斷上傳檔案格式

$string="txt";

$extend = pathinfo($_files['userfile']['name']);

$extend = strtolower($extend["extension"]);

if ($extend!=$string)";

}else

if(@move_uploaded_file($_files['userfile']['tmp_name'],$uploadfile))else

if (perform_trans_ops($conn,$content))";

}else";

sqlsrv_rollback($conn);//事務檢查異常,回滾事務

}}else

}sqlsrv_close($conn);

}else";}}

function perform_trans_ops($conn,$content)";

return false;

}//資料庫操作

$sql = "insert into bio_information(info_id,info_title,info_author,info_origin,info_theme,info_keyword,info_pubtime,info_abstract,info_format,info_isfull,info_isdown,info_trade,info_category,info_path,info_remark,info_content,info_contentblock)

values('".(int)$str[0]."','".$str[1]."','".$str[2]."','".$str[3]."','".$str[4]."','".$str[5]."','".$str[6]."','".$str[7]."','".$str[8]."','".$str[9]."','".$str[10]."','".$str[11]."','".$str[12]."','".$str[13]."','".$str[14]."','".$str[15]."','".$str[16]."')";

$stmt = sqlsrv_query( $conn, $sql , $params, $options );

if ($stmt===false)

";return false;}}

return true;

sqlsrv_free_stmt($stmt);

}

PHP讀取EXCEL檔案寫入資料庫

php讀取ecel檔案寫入資料庫功能的實現使用到了phpexcel類庫。完整 如下 uploadfile upload files basename files userfile name message if move uploaded file files userfile tmp name u...

PHP寫入txt檔案

myfiletoread fopen txt readme.txt r or die unable to open file myfileread fread myfiletoread,20 myfiletowrite fopen txt writeme.txt a or die unable to...

python 寫入 讀取txt檔案

with open desc.txt w as f f.write 我是個有想法的小公舉 這句 自帶檔案關閉功能。比較常用的檔案讀寫選項 r 以讀的方式開啟,只能讀檔案,若檔案不存在,則發生異常 w 以寫的方式開啟,只能寫檔案,如果檔案不存在,建立該檔案 如果檔案已存在,先清空,再開啟檔案 rb 以...