sdssds
$i $buffer";
if($i < $line )
continue;
if($i > $line )
break;
$name = substr($buffer, 0, -2);
if($name[0] === '')
continue;
echo $buffer;
$pr_arr = explode("\t", $buffer);
print_r($pr_arr );
$name = trim($pr_arr [0]);
$type = trim($pr_arr[1]);
$reference = trim($pr_arr[2]);
$from = trim($pr_arr[3]);
$language = trim($pr_arr[4]);
$desc= trim($pr_arr[5]);
$gender = trim($pr_arr[6]);
$native = trim($pr_arr[7]);
$add_info = trim($pr_arr[8]);
//$filename = trim($pr_arr[9]);
$origin= trim($pr_arr[11]);
$ipa = trim($pr_arr[12]);
if(strlen($reference) == 0)
$reference = $_GET['reference'];
if(strlen($from) == 0)
$from = $_GET['from'];
if(strlen($language) == 0)
$language = $_GET['language'];
if ($desc =='')
{
$desc = 'Audio Only';
}
if(strcasecmp($desc,'audio only') == 0 )
$pron_table = "0";
else
$pron_table = "1";
if(strcmp($gender,'m') == 0 )
$gender = 1;
if(strcmp($gender,'Male') == 0 )
$gender = 1;
else if(strcmp($gender,'f') == 0 )
$gender = 2;
else if(strcmp($gender,'Female') == 0 )
$gender = 2;
else if(strcmp($gender,'NA') == 0 )
$gender = -1;
else if(strcmp($gender,'x') == 0 )
$gender = 3;
else
$gender = -1;
//$gender = -1;
//$type = "First Name";
$a = sprintf("%02d", $i);
$nomusicfilename = "NoMusic-$a.mp3";
echo $nomusicfilename;
//echo $buffer;
//echo "*";
//echo ",";
echo "name = ";
echo $name;
echo "*";
echo ",gender=";
echo $gender;
echo ",type=";
echo $type;
echo ",reference=";
echo $reference;
echo ",from=";
echo $from;
echo ",language=";
echo $language;
echo ",filename=";
echo $filename;
echo ",desc=";
echo $desc;
echo ",add_info=";
echo $add_info;
echo ",pron_table=";
echo $pron_table;
echo ",native=";
echo $native;
echo "*";
echo $origin;
echo "*";
"
";
if(checkifExist($name, $reference))
{
echo "
Record exist, Cannot add";
?>
rename $f1 $f2";
if (file_exists($f1))
{
echo "The file $filename exists";
}
else
{
echo "The file $filename does not exist";
}
if(rename($f1, $f2) == FALSE)
{
echo "
Cannot rename, delete the record";
break;
}
if(rename($f2, $f1) == FALSE)
{
echo "
Cannot rename, delete the record";
break;
}
echo "
origin = $origin";
$id = saveNameInfoInDB1($name, $from , $type, $language, $gender, $add_info, $origin);
$nameid = saveInfoInDB($name, $desc, $pron_table, $_SERVER['REMOTE_ADDR'],$id, $reference );
$filename_part1 = $nameid."_". getMilliseconds();
echo "
rem filename_part1 = ". $filename_part1 ;
$mp3name = $filename_part1.".mp3";
echo "
rem mp3name = ".$mp3name ;
$f1 = "./uploads/meenakshi/$filepath/$filename";
$f2 = "/var/www/pronouncenames.com/mp3/$mp3name";
echo "
ren $filename $mp3name, $name, $i";
if(rename($f1, $f2) == FALSE)
{
echo "
Cannot rename, delete the record";
// break;
}
$voiceid = addVoice2DB($nameid, $mp3name);
addVoiceIdName($nameid, $voiceid);
if(strlen($native)> 0)
add2NativeDatabase($nameid, $name, $native);
if(strlen($ipa) > 0)
add2IPA($nameid, $ipa);
if($reference == "Viv")
$origin = 'English';
?>
Error: cannot get the handle for the file\n";
}
*/
fclose($handle);
function saveNameInfoInDB1($name, $fromwhere, $typeofname, $language, $gender, $add_info, $origin)
{
global $dbname, $dbuser, $dbpswd , $dbserver;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
{
return FALSE;
}
$query = sprintf("insert into nameinfo (name, user_from, typeofname, language, timestamp, gender, add_info, origin ) values ('%s', '%s', '%s', '%s', CURRENT_TIMESTAMP, '%s','%s','%s')",
mysqli_real_escape_string($link, $name),
mysqli_real_escape_string($link, $fromwhere),
mysqli_real_escape_string($link, $typeofname),
mysqli_real_escape_string($link, $language),
mysqli_real_escape_string($link, $gender),
mysqli_real_escape_string($link, $add_info),
mysqli_real_escape_string($link, $origin)
);
echo "
rem ".$query;
$result = mysqli_query($link, $query) or die("failed1 = " .$query);
$id = mysqli_insert_id($link);
if (!$result)
return FALSE;
mysqli_close($link);
return $id;
}
function saveInfoInDB($name, $desc, $pron_table, $ip, $nameinfoid, $author )
{
global $dbname, $dbuser, $dbpswd , $dbserver;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
{
return FALSE;
}
//mysql_select_db($dbname);
$query = sprintf("insert into names (name, description, pron_table, ip, nameinfoid, insert_timestamp, reference) values ('%s','%s',%d, '$ip', $nameinfoid, CURRENT_TIMESTAMP, '$author')",
mysqli_real_escape_string($link, $name),
mysqli_real_escape_string($link, $desc),
mysqli_real_escape_string($link, $pron_table));
//echo "
rem ".$query;
$result = mysqli_query($link, $query) or die("failed = " .$query);
$id = mysqli_insert_id($link);
if (!$result)
return FALSE;
mysqli_close($link);
return $id;
}
function addVoice2DB($nameid, $filename)
{
global $dbname, $dbuser, $dbpswd, $dbserver ;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
return FALSE;
//mysql_select_db($dbname);
$query = sprintf("insert into voices (nameid, filename) values ('%s','%s')",
mysqli_real_escape_string($link, $nameid),
mysqli_real_escape_string($link, $filename));
//echo "
rem ".$query;
$result = mysqli_query($link, $query) or die("");
$id = mysqli_insert_id($link);
if (!$result)
return FALSE;
mysqli_close($link);
return $id;
}
function add2NativeDatabase($nameid, $name, $native)
{
global $dbname, $dbuser, $dbpswd, $dbserver ;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
return FALSE;
//mysql_select_db($dbname);
$query = sprintf("insert into namesinnative (nameid, name, native) values (%s,'%s','%s')",
mysqli_real_escape_string($link, $nameid),
mysqli_real_escape_string($link, $name),
mysqli_real_escape_string($link, $native));
//echo "
rem ".$query;
$result = mysqli_query($link, $query) or die("");
if (!$result)
return FALSE;
mysqli_close($link);
return TRUE;
}
function add2IPA($nameid, $ipa)
{
global $dbname, $dbuser, $dbpswd, $dbserver ;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
return FALSE;
//mysql_select_db($dbname);
$query = sprintf("insert into IPA (nameid, ipa) values ('%s','%s')",
mysqli_real_escape_string($link, $nameid),
mysqli_real_escape_string($link, $ipa));
//echo "
rem ".$query;
$result = mysqli_query($link, $query) or die("");
if (!$result)
return FALSE;
mysqli_close($link);
return TRUE;
}
function getMilliseconds()
{
list($micro, $second) = explode(' ',microtime());
$ms = ($second *1000 + $micro * 1000);
return sprintf("%u", $ms);
}
function addVoiceIdName($nameid, $voiceid)
{
global $dbname, $dbuser, $dbpswd, $dbserver ;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
return FALSE;
//mysql_select_db($dbname);
// $query = "update names set voiceid = $voiceid where id = $nameid";
$query = sprintf("update names set voiceid = %s where id = %s",
mysqli_real_escape_string($link, $voiceid),
mysqli_real_escape_string($link, $nameid)
);
echo $query;
$result = mysqli_query($link, $query) or die("die");
if (!$result)
return FALSE;
mysqli_close($link);
return TRUE;
}
function checkifExist($name, $reference)
{
$cnt;
global $dbname, $dbuser, $dbpswd, $dbserver ;
$link = mysqli_connect($dbserver, $dbuser, $dbpswd, $dbname) or die("die");
if (!$link)
return FALSE;
// mysql_select_db($dbname);
$query = "select count(*) from names where names.name = '%s' and reference = '%s'";
$query = sprintf($query, mysqli_real_escape_string($link, $name), mysqli_real_escape_string($link, $reference));
echo "
".$query;
$result = mysqli_query($link, $query) or die("");
while($line = mysqli_fetch_array($result, MYSQLI_BOTH))
{
$cnt = $line[0];
}
mysqli_free_result($result);
mysqli_close($link);
if(intval ($cnt) > 0)
return TRUE;
return false;
}
?>