Jump to content

[SOLVED] Problem with uploading csv file to the mysql database


sandhya

Recommended Posts

Hi all, please give me a solution for this. I have converted an Excel file into .csv file. And browsed from the form with the form field named 'csvfile'. And i'm trying to upload the form using the following code.

 

$file1=$_FILES['csvfile']['name'];

$lines = file($file1);

foreach ($lines as $line) {

  $cols = explode(';', $line);

    mysql_query("INSERT INTO aop_class (catid, orgname, address, city, country, phone, description) VALUES(".trim($cols[0]).",'".trim($cols[1])."','".trim($cols[2])."','".trim($cols[3])."','".trim($cols[4])."','".trim($cols[5])."','".trim($cols[6])."')") or

    die(mysql_error());

 

But, after execution i'm getting the following wornings

 

Warning: file(): Unable to access class1.csv in /home/sphoor21/public_html/mitrahelp/admin/classified.php on line 165

 

Warning: file(class1.csv): failed to open stream: Permission denied in /home/sphoor21/public_html/mitrahelp/admin/classified.php on line 165

 

So, Please tell me what is happening her. How can I upload a csv file to the database. Thanks in advance.

Consider giving them limited access to phpMyAdmin then...

 

It uses LOAD DATA INFILE method, so it is much faster, than INSERTing row by row.

 

If you want to stick with your own script, perhaps you should also consider uploading csv first, and then using LOAD DATA INFILE.

Basically it's not possible to give them the access to php MyAdmin in this case. So, Please give me a solution.

Michl has offered you a solution

If you want to stick with your own script, perhaps you should also consider uploading csv first, and then using LOAD DATA INFILE.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.