Jump to content

fgets() returns bool


The Little Guy

Recommended Posts

I can not get this method to work.

 

When I get to while($buffer = fgets($handle) !== false){ when I dump my buffer, All I get is bool(true). Everything before the while loop works, but the while does not. Any Ideas why?

 

- Line 1 contains the column names

- Line 2+ contains my data I want to save.

- The file is a CSV

- $this->GetStateValue is a session of the file string: "../data/forms/myfile.csv".

 

public function ocd_view(){
	$location = $this->GetStateValue("authorize_fraud_file");
	$handle = fopen($location, 'rb');
	$line1 = fgets($handle);
	$line1 = preg_replace("/ |\/|-/", "", $line1);
	$items = explode(",", $line1);
	$tbl_cols = "";
	$tbl_cols_sel = "";
	foreach($items as $item){
		$tbl_cols .= $this->enc($item)." char(100),";
		$tbl_cols_sel .= $this->enc($item).",";
	}
	$tbl_cols = trim($tbl_cols,",");
	$tbl_cols_sel = trim($tbl_cols_sel,",");
	$this->db->ExecuteSql("create temporary table authorize_credit_card_fraud ($tbl_cols);");
	while($buffer = fgets($handle) !== false){
		var_dump($buffer);
		$items = explode(",",$buffer);
		$tbl_rows = "";
		foreach($items as $item){
			$tbl_rows .= "'".$this->enc($item)."',";
		}
		$tbl_rows = trim($tbl_rows,",");
		echo $tbl_rows."<br>";
		$this->db->ExecuteSql("insert into authorize_credit_card_fraud ($tbl_cols_sel) values ($tbl_rows)");
		//echo count($items)."<br>";
	}
	$sql = $this->db->ExecuteSql("select m.member_id, concat(first_name, ' ', last_name) as full_name from authorize_credit_card_fraud accf left join members m on (accf.CustomerID = m.member_id)
		where accf.CustomerFirstName != m.first_name and accf.CustomerLastName != m.last_name");
	echo mysql_error();
	$i = 1;
	echo "<a href='./csv_fraud.php'>Again</a>";
	while($row = mysql_fetch_assoc($sql)){
		echo $i.". ".$row['full_name']."<br />";
		$i++;
	}
}

Link to comment
https://forums.phpfreaks.com/topic/242850-fgets-returns-bool/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.