I am trying to upload a file so that I can add the data it contains into mysql database.
this is the code I have
require_once ('../mysql_connect.php');//connect to the database
$uploadDir = '/home/888/***/htdocs/***/***/upload/';
$uploadFile = $uploadDir . $_FILES['ClientCsvFile']['name'];
print "<pre>";
if (is_uploaded_file($_FILES['ClientCsvFile']['tmp_name']))
{
move_uploaded_file($_FILES['ClientCsvFile']['tmp_name'], $uploadFile);
}
else
{
print "Not Possible To Upload Data! Please Try Again";
}
print "</pre>";
$filename = "Client.csv";
$fp = fopen($filename,"rb") or die('could not open file!');
while (!feof($fp)){
$data = fgetcsv($fp,500000);
$ClientId = $data[0];
$ConcesRef = $data[1];
$CoName = $data[2];
$Addr1 = $data[3];
$Addr2 = $data[4];
$Addr3 = $data[5];
$Town = $data[6];
$County = $data[7];
$Postcode = $data[8];
$Phone = $data[9];
$Fax = $data[10];
$sql = "REPLACE INTO tblClient (ClientId, ConcesRef, CoName, Addr1, Addr2, Addr3, Town, County, Postcode, Phone, Fax)
VALUES ('$ClientId', '$ConcesRef', '$CoName', '$Addr1', '$Addr2', '$Addr3', '$Town', '$County', '$Postcode', '$Phone', '$Fax')";
$result = mysql_query($sql)
or die(mysql_error());
}
$_FILES['ClientCsvFile'] comes from a html form on a previous page.
when I run this code I get my error message Not Possible To Upload Data! Please Try Again which is the else part of the first if .
I know that this is because for some reason the file cannot be found on the local server. but I don;t know how to correct this - can anyone see what I have done wrong or what I am missing - thanks.