Roundcube Community Forum

 

Import address book from csv file

Started by namit, October 19, 2006, 02:55:52 PM

Previous topic - Next topic

namit

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) . &quot;: &quot; . mysql_error($conn). &quot;\n&quot;;

///Fin connection

$user_id $_GET['user_id'];
$file $_GET['file'];

if(
$user_id == &quot;&quot; || $file == &quot;&quot;)
{
echo &quot;You have no user id $user_id<br />OR files&quot;;
}
if(
$user_id != &quot;&quot; || $file != &quot;&quot;)
{

echo 
$user_id;
echo &
quot;<br />$file&quot;;

$row 1;
$handle fopen($file, &quot;r&quot;);
echo &
quot;$handle&quot;;

while ((
$data fgetcsv($handle1000, &quot;,&quot;)) !== FALSE)
{

echo &quot;<br />&quot;;

$row++;

$name $data[0];
$email $data[1];

echo &quot;<b>Name: </b>&quot; . $name. &quot;\n&quot;;
echo &quot;<B>Email:</B> &quot; . $email . &quot;\n&quot;;

$query = &quot;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''''''' );&quot;;
echo &quot;<br />&quot;;

mysql_query($query$conn);
echo mysql_errno($conn) . &quot;: &quot; . mysql_error($conn) . &quot;\n&quot;;

}

fclose($handle);

}


?>

CReber

Can you give me a sample of the csv file? Don't wanna crash the db ;)

Thanks!

namit


Nonsense

May seem like a stupid question, but where exactly (in which lines) do I insert username and file?


CReber

link doesn't work :P just quote an exact sample of a csv file you would recommend! only 3 lines...

thanks anyway....

namit


Create a directory on your server called cvsupload.php
upload the cvs file to your server
format is
bob,[email protected]
chris noen,[email protected]

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

Nonsense

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:

CReber

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][email protected][/email]
0:
Name: Dublin - Billy Email: [email][email protected][/email]
0:
Name: Dublin - William Email: [email][email protected][/email]


The output log seems ok, so what else can that be?

namit

Can you check the sql tables and see if the are being entered?

You also have to logout and then login to roundcube.

Nonsense


namit

in my code or your code? if it was my code give it to me and i will change my code.

Nonsense


rantdepot


klemen

I have an csv file format:

firstname,surname,name,,[email protected],,,,,,,,,,,,,,,,,,,,,,,

I get surname where I need email. How to edit the script to get right insert.

thanks.