Jump to content

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


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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.