Upload PHP file that passes data to MYSQL

Asked

Viewed 577 times

0

It will be difficult to explain what I want but I will try to summarize in 2 small paragraphs.

Come on

I have a script that passes the file data .CSV and .TXT to the database MYSQL, but it only works when I put the name of my document and the document itself hosted along with it, ie I have a file importar.csv and importar.php, in the importar.php needs to be set the file importar.csv.

But what do you want to do?

I would like it to work with upload php file, ie the person (anyone) who has access to the upload area, send the file .CSVor .TXTand instead of the archive importar.php set the file importar.csv, he set the upload file.

If you don’t understand, please leave a comment and I’ll explain it better.

And the importar.php how are?

$tabela = "n_emails";
$arquivo = 'importar.csv';

$arq = fopen($arquivo,'r');

while(!feof($arq))
for($i=0; $i<1; $i++){
if ($conteudo = fgets($arq)){
    $ll++; // $ll 
    $linha = explode(';', $conteudo);// 
}

$sql = "INSERT INTO $tabela (ativo, email) VALUES ('$linha[0]', '$linha[1]')";
$result = mysql_query($sql) or die(mysql_error());
$linha = array();
}
echo "quantidade de linhas importadas = ".$ll;

I hope you have passed on all the information necessary for the understanding of all, I appreciate the help or the haha attempt.

  • 1

    you need to create a form with enctype, an input file and uses the function move_upload_file

  • thank you @rray did not understand much, but I gave a studied and it is very simple at the end, I thank you

  • Nice to see you’re making progress :D

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.