Roundcube Community Forum
Third Party Contributions => Old Style Plug-Ins => Topic started by: namit on October 19, 2006, 02:55:52 PM
-
Pass down the name of the file you want
And the users id that is in the sql table
csv layout
Name, Email
Hope it helps ya all.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'roundcubemail';
mysql_select_db($dbname, $conn);
echo mysql_errno($conn) . ": " . mysql_error($conn). "\n";
///Fin connection
$user_id = $_GET['user_id'];
$file = $_GET['file'];
if($user_id == "" || $file == "")
{
echo "You have no user id $user_id<br />OR files";
}
if($user_id != "" || $file != "")
{
echo $user_id;
echo "<br />$file";
$row = 1;
$handle = fopen($file, "r");
echo "$handle";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
echo "<br />";
$row++;
$name = $data[0];
$email = $data[1];
echo "<b>Name: </b>" . $name. "\n";
echo "<B>Email:</B> " . $email . "\n";
$query = "INSERT INTO `contacts` ( `contact_id` , `user_id` , `changed` , `del` , `name` , `email` , `firstname` , `surname` , `vcard` ) VALUES ( '', '$user_id', '1985-09-15 00:00:00', '0', '$name', '$email', '', '', '' );";
echo "<br />";
mysql_query($query, $conn);
echo mysql_errno($conn) . ": " . mysql_error($conn) . "\n";
}
fclose($handle);
}
?>
-
Can you give me a sample of the csv file? Don't wanna crash the db ;)
Thanks!
-
csv layout
Name, Email
-
May seem like a stupid question, but where exactly (in which lines) do I insert username and file?
-
well you will have on your webserver the csv file then you will have
http://yourwebsite.com/cvsupload.php?user_id=THE_USER_ID_THAT_U_HAVE_IN_SQL_TABLE&file=FILE_NAME
-
link doesn't work :P just quote an exact sample of a csv file you would recommend! only 3 lines...
thanks anyway....
-
Create a directory on your server called cvsupload.php
upload the cvs file to your server
format is
bob,boobs@boobs.com
chris noen,namit@something.org
create a file called cvsupload.php in the direcotry csv-upload.
find in the sql tables the userid within the roundcube tables then replaec that iin the link below.
replace yourwebsite.com with your website
http://yourwebsite.com/cvsupload.php?user_id=THE_USER_ID_THAT_U_HAVE_IN_SQL_TABLE&file=FILE_NAME
-
That didn't work.
0: user_id (my emailaddress)
file.csvResource id #3
Name: Name Name Email: email
0:
Name: Name Name Email: email
0:
-
same like me! the script only imports the first 3 contacts and then it stops...
0: 1
contacts.csvResource id #3
Name: Berlin - Michael Email: [email]michael@berlin.de[/email]
0:
Name: Dublin - Billy Email: [email]billy@dublin.com[/email]
0:
Name: Dublin - William Email: [email]william@dublin.com[/email]
The output log seems ok, so what else can that be?
-
Can you check the sql tables and see if the are being entered?
You also have to logout and then login to roundcube.
-
Solved.
It was a typo.
Thanks.
-
in my code or your code? if it was my code give it to me and i will change my code.
-
My code. So don't worry.
-
Worked well, thanks! 8)
-
I have an csv file format:
firstname,surname,name,,name@email.com,,,,,,,,,,,,,,,,,,,,,,,
I get surname where I need email. How to edit the script to get right insert.
thanks.
-
I figured it out, if anyone need it:
$firstname = $data[0];
$surname = $data[1];
$name = $data[2];
$email = $data[3];
echo "name: " . $firstname. "\n";
echo "surname: " . $surname. "\n";
echo "name:" . $name. "\n";
echo "email:" . $email. "\n";
$query = "INSERT INTO `contacts` ( `contact_id` , `user_id` , `changed` , `del` , `name` , `email` , `firstname` , `surname` , `vcard` ) VALUES ( '', '$user_id', '1985-09-15 00:00:00', '0', '$name', '$email', '$firstname', '$surname', '' );";
echo "
";
-
Thanks a lot!
Works perfektly! ;D
I save one hour or more !
Thanks