afidegnum
Posts: 16
|
| Posted: 03/04/2008, 9:52 AM |
|
Hello, good morning,
I am writing an event code to open and read a csv file. Before Process: and I god the following error
Catchable fatal error: Object of class clsFileUpload could not be converted to string in C:\wamp\www\responser\prospects_imp_events.php on line 27
this is the following code:
it is a file upload file component,
=============================================================
<?php
//BindEvents Method @1-113D0652
function BindEvents()
{
global $importForm;
$importForm->FileUpload1->CCSEvents["BeforeProcessFile"] = "importForm_FileUpload1_BeforeProcessFile";
}
//End BindEvents Method
//importForm_FileUpload1_BeforeProcessFile @3-DBCE0183
function importForm_FileUpload1_BeforeProcessFile(& $sender)
{
$importForm_FileUpload1_BeforeProcessFile = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $importForm; //Compatibility
//End importForm_FileUpload1_BeforeProcessFile
//Custom Code @9-2A29BDB7
if(!strlen($Container->FileUpload1->GetValue()))
{
$import->Errors->addError("No Upload File - Please try again ") ;
} else {
$file = "$Container->FileUpload1->TemporaryFolder.$Container->FileUpload1->GetValue()";
{
$import->Errors->addError("Error Processing File - Please try again ") ;
}
$db = new clsDBConnection1();
$handle = fopen($file,"r");
$row = 1;
$handled = fopen("$handle", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
$SQL = "INSERT INTO prospects (pros_fname,pros_lname,pros_email) values('$data[0]','$data[1]','$data[2]')";
$db->query($SQL);
$db->close();
}
}
fclose($handled);
}
//End Custom Code
//Close importForm_FileUpload1_BeforeProcessFile @3-F4C24C40
return $importForm_FileUpload1_BeforeProcessFile;
}
//End Close importForm_FileUpload1_BeforeProcessFile
?>
|
 |
 |
|