Link to home
Start Free TrialLog in
Avatar of Geerd
Geerd

asked on

Import of CSV file with PHP works offline but not with my ISP

Dear All,

I'm trying to import 2 CSV files from a local computer to the database of my ISP.
The code I wrote works fine in my offline develop environment but it does not work when I upload the files to the server of my ISP.

When running the code online it loops and gives me 1.5 million empty records in the first table.

Any help would be welcome.

Kind regards.

G.


File1.php
ASKER CERTIFIED SOLUTION
Avatar of hax1
hax1
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Geerd
Geerd

ASKER

Thank you hex1.

I do have a couple of questions about how to implement your solution.

$uploads_dir = 'your/upload/dir';

What should I replace 'your/upload/dir' with? Should I use a local path ie: c:\upload\  from my local computer or should I use 'http://www.mysite.com/uploaddir/'

$tmp_name = $_FILES['filename1']['tmp_name'];

Where did the tmp_name come from? I only have the filename.

$name = $_FILES['filename1']['name'];

Again, where does the 'name' come from?

Thanks again for helping me.


hey!

you need to choose neither, but the directory of the server where your files are being stored.

you can try setting it relative (f.e. $uploads_dir='./uploads')

(be sure to create the folder in the directory where your script lies in and set the permissions so that the web server can write in there (777 f.e.)).

the filename and temp name comes from your upload from, the form field should look like this:

<input type="file" name="filename1" id="filename1" />
<input type="file" name="filename2" id="filename2" />

and be sure that the form enctype is set to multipart/form-data

<form action="yourphpfile.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
Avatar of Geerd

ASKER

I made the changes you've suggested but there is still one issue.

The input type 'file' statements makes me select a file from my local PC. I cannot type a file name manually. I made the upload directory on the server and placed the files that need to be imported there. But when I click the 'file' button I can only choose local files.

Any ideas?
how big are the 2 files ? You should always think about the php.ini limitation on upload files, witch default is 8MB.

You can always print out the errors you get from file uploading.
Here's a little help.

after you send it to your php, from the form use this.

<form action="action.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input type="file" name="filename1" id="filename1" />
<input type="file" name="filename2" id="filename2" />

</form>

// ######## action.php
<?php
$file1 = $_FILES['filename1'];
$file2 = $_FILES['filename2'];

$upErrors = array(
                UPLOAD_ERR_OK                     => "No Error.",
            UPLOAD_ERR_INI_SIZE          => "File is too large.",
            UPLOAD_ERR_FORM_SIZE      => "File is too large.",
            UPLOAD_ERR_PARTIAL        => "Partial upload.",
            UPLOAD_ERR_NO_FILE        => "No file.",
            UPLOAD_ERR_NO_TMP_DIR     => "No Temporary Directory.",
            UPLOAD_ERR_CANT_WRITE         => "Can't write to disk.",
            UPLOAD_ERR_EXTENSION        => "File upload stopped by extension."

);

//now for each file, apart from name, tmpname
echo $upErrors[$file1['error']];



?>
 now you should see what prints out. I'm sure you can take it from there