Re: Re: Csv issue
| From: | Shawn McKenzie | Date: | Tue, 14 Oct 2008 15:21:02 +0000 |
| Subject: | Re: Re: Csv issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281888@lists.php.net to get a copy of this message | ||
admin@buskirkgraphics.com wrote:
> OKay now i am really stumped.
> Notice: Undefined index: filename
> When clearly I have it being set in the form with the file.
> Any suggestions?
>
>
>
> admin@buskirkgraphics.com wrote:
>
>> I am using a form to select a csv file and then import it into mysql and
>>
> maybe im just drawling a blank here. But why is it blowing up.
>
>> This thing loads like 14 million records into the database and I am clue less
>>
> how it can do that with a 2 record csv file.
>
>> <form enctype='multipart/form-data' action=? method=post>
>> Upload:<input type=file name=filename>
>> <input type=submit value='Upload'></form>
>>
>>
>> $row = 1;
>> $filename = $_POST['filename'];
>> $handle = fopen("$filename", "r");
>> while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
>> {
>> $num = count($data);
>> echo "<p> $num fields in line $row: <br /></p>\n";
>> $row++;
>> }
>> fclose($handle);
>> print "Import done";
>>
>> This will produce millions of lines until i go in and stop the process on the
>>
> server. I know its stupid but im drawling a blank as to why its doing this. The
> csv file has 2 lines in period.
>
>> <p> 0 fields in line 1: <br /></p>
>> <p> 0 fields in line 2: <br /></p>
>> ect for millions of records.
>>
> Try:
>
> print_r(file($_POST['filename']));
>
> And see if you get what you expect. You might also want to have
> error_reporting at its highest and display_errors also.
>
> -Shawn
>
>
Please reply to the list. I missed it the first time around, but you
need to use the $_FILES array:
http://php.net/manual/features.file-upload.php
-Shawn