This function is to do batch uploading into database. I will provide the skin file in my next post. Basically the file uploaded is in CSV format.
function batch_upload() {
global $user;
// get vars & $post vars
$this->get = &$GLOBALS[HTTP_GET_VARS];
$this->post = &$GLOBALS[HTTP_POST_VARS];
// see if submitted form
$submit=$this->post;
if(!$submit){
header("location:upload.html");
} else {
$farg=&$GLOBALS[HTTP_POST_FILES];
if ($farg) {
foreach(array_keys($farg) as $fdn) {
if ($farg[$fdn][tmp_name]) {
$fname = $farg[$fdn][tmp_name];
exec("chmod 744 $fname");
$ref = $user[_id]."_".time(); //to be use to indentify record
//create a tmp_table before hand
//assign all the previous record as old record. so that will not confuse with new records
mysql_query("update tmp_table set is_new = 'no'");
$cmd = "LOAD DATA INFILE '$fname' INTO TABLE tmp_table FIELDS TERMINATED BY ',' ENCLOSED BY '".'"'."' LINES TERMINATED BY '\r\n' (field1,field2,field3,field4)";
$result=mysql_query($cmd);
//distinguish new record from the new one
mysql_query("update tmp_table set ref = '$ref' where is_new = 'yes'");
//start to transfer into real table
mysql_query("insert into real_table (field1,field2,field3,field4) select field1,field2,field3,field4 from tmp_table where ref='$ref'");
header("location:doneupload.php");
}
}
}
}
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment