Problem assigning path var to $fcontents = file ($userfile);
Posted: Mon Apr 20, 2009 2:36 pm
I seem to be having a problem assigning a path variable within file(). For some reason when I assign a path like $fcontents = file ($path/$userfile[/b]); it does not seem to work. Does anyone see a problem here (besides me being new to php)?
$path = '/usr/local/apache2/htdocs/files';
//Insert file into table
$fcontents = file ($path/$userfile);
// expects the csv file to be in the same dir as $path
$counter = 0;
$success = 1;
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "insert into $tablename values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo "<br />" . $sql . "<br />";
$counter = $counter + 1;
if(mysql_error()) {
$success = 0;
echo "WARNING, there were errors: " . mysql_error() . "<br />";
}
}
if ($success == 0) {
echo "<br />" . "Please address the errors. " . "<br />";
}
else {
echo "<br />". "Total records inserted into table " . $tablename . ": " . $counter . "<br />";
}
$path = '/usr/local/apache2/htdocs/files';
//Insert file into table
$fcontents = file ($path/$userfile);
// expects the csv file to be in the same dir as $path
$counter = 0;
$success = 1;
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$sql = "insert into $tablename values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo "<br />" . $sql . "<br />";
$counter = $counter + 1;
if(mysql_error()) {
$success = 0;
echo "WARNING, there were errors: " . mysql_error() . "<br />";
}
}
if ($success == 0) {
echo "<br />" . "Please address the errors. " . "<br />";
}
else {
echo "<br />". "Total records inserted into table " . $tablename . ": " . $counter . "<br />";
}