• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

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.


  • 2
  • 2
1 Solution
Probably has to do with how you handle the file upload.


                     $handle = fopen("$filename", "r");

try ->  

        $uploads_dir = 'your/upload/dir';
        $tmp_name = $_FILES['filename1']['tmp_name'];
        $name = $_FILES['filename1']['name'];
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
        $handle = fopen("$uploads_dir/$name", "r");
GeerdAuthor Commented:
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.


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">
GeerdAuthor Commented:
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" />


// ######## action.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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now