jrobles Posted November 14, 2009 Share Posted November 14, 2009 I am uploading a CSV file and loading the contents into a mysql table. The CSV contains credit card info so I am encrypting the cc string before i insert it into the table. That all works fine, but I have to keep a copy of the original CSV file on my server and I dont want a CSV file siting there with a bunch of credit card numbers in it, just waiting to get stolen. How can I replace the CC string inside the CSV after i insert the records and before I fclose()? here is some of my code: //UPLOAD THE FILE BEING PROCESSED $uploaddir = 'uploaded_files/'; $uploadfile = $uploaddir . basename($_FILES['file']['name']); move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile); //RENAME THE FILE $rand_num = mt_rand(5,9999999999); $new_file = $uploaddir. date("mdY"). $rand_num.".csv"; rename($uploadfile,$new_file); //DECLARE $HANDLE AS OPEN .CSV FILE $handle = fopen("$new_file", "r"); //INSERT RECORDS WITH CC VALIDATION $cnt = 0; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { //INSERT INTO INVENTORY TABLE $import="INSERT INTO inventoryTable(customerid,imbatchid, importdate,fname, mname, lname, phone, address1, address2, city, state, zip) VALUES(CONCAT(substring('$data[2]',1,1),substring('$data[4]',1,3),substring('$data[0]',1,1)),'$batchid',NOW(),'$data[0]','$data[1]','$data[2]', '$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]')"; mysql_query($import) or die(mysql_error()); //VALIDATE CC if (checkCreditCard ($data[9], $data[10], $ccerror, $ccerrortext)) {$ccerrortext = 'This card has a valid format'; $ccerror=9;} //ENCRYPT CC NUMBER $cc = encrypt($data[9]); //INSERT CC DATA $cc_query="INSERT INTO creditCards(customerID,CardNumber,ValidationStatus,ValidationDesc,ExpireMonth,ExpireYear,CardType)VALUES(CONCAT(substring('$data[2]',1,1),substring('$data[4]',1,3),substring('$data[0]',1,1)),'$cc',$ccerror,'$ccerrortext','$data[11]','$data[12]','$data[10]')"; mysql_query($cc_query) or die(mysql_error()); } //CLOSE THE .CSV FILE fclose($handle); Quote Link to comment Share on other sites More sharing options...
jrobles Posted November 14, 2009 Author Share Posted November 14, 2009 ... Quote Link to comment Share on other sites More sharing options...
jrobles Posted November 16, 2009 Author Share Posted November 16, 2009 Quote Link to comment Share on other sites More sharing options...
jjacquay712 Posted November 17, 2009 Share Posted November 17, 2009 preg_replace() Quote Link to comment Share on other sites More sharing options...
jrobles Posted November 18, 2009 Author Share Posted November 18, 2009 could you point me in the right direction with the syntax? i'm a noob and cant find a good tut for preg_replace Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.