Joomla.it Forum
Joomla! 2.5 (versione con supporto terminato) => Joomla! 1.6/1.7/2.5 => : ird 20 Feb 2014, 12:43:54
-
Ciao a tutti sto cercando di creare un php esterno a joomla per importare un file csv contente indirizzi email e nomi su tabella mysql.
Lo script ce l'ho, ora mi serve ottenere l'userid dell'utente loggato su Joomla (joomla 2.5), così da avere l'user id su un campo apposito nella tabella mysql, questo perchè poi dal form di un componente vorrei richiamare per ogni utente i propri dati caricati dal csv utilizzando una query tipo ""SELECT name, email FROM tabelladaticsv WHERE userid=") (questa parte del richiamare i dati so già come farla piu o meno)
Sapete dirmi come potrei fare? Anticipo che non sono una cima in scripting XD
Ringrazio anticipatamente per ogni eventuale aiuto :)
Lo script che ho è il seguente:
<?php
//connect to the database
$connect = mysql_connect("localhost","username","password");
mysql_select_db("mydatabase",$connect); //select the table
//
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO contacts (contact_first, contact_last, contact_email) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
//
//redirect
header('Location: import.php?success=1'); die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <?php if (!empty($_GET[success])) { echo "Your file has been imported.[br /][br /]"; } //generic success notice ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> Choose your file: [br /] <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html>