|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
Parsing CSV files
Here is an alternate resource for parsing CSV files. Take a look at the biterscripting sample script SS_CSV. It shows how to parse CSV files. It may or may not work for your purposes.
Randi |
|
#17
|
|||
|
|||
|
Hey Randi,
I'm trying to make the below part work: PHP Code:
As mentioned earlier, I need this to happen on submit and parse the csv file I upload in the upload text box with browse button. Sorry, I checked out the code for biterscripting sample script SS_CSV coz I didn't understand the code entirely. Any help would be great! |
|
#18
|
|||
|
|||
|
if its a file you are uploading, check out pretty much any file upload tutorial. they will show you to use $_FILE instead of $_POST to access the file.
|
|
#19
|
|||
|
|||
|
Hey,
Can't I read the uploaded file directly rather than saving it in temp location in PHP? Probably that's what would work in my case or maybe that's what I'm trying to do so long. |
|
#20
|
|||
|
|||
|
if it is a file you are uploading via a form (an uploaded file passed into a form using the <input type="file"> tag where you click browse and find the file locally on your computer) then you would need to use $_FILE to either read it from the temp directory or move it from the temp directory and then read the file. If it is a file that has already been uploaded by some other method like ftp or you just create a new file then you can just access the file locally by just using the relative path/name.
|
|
#21
|
|||
|
|||
|
The problem, I don't know what I'm missing in the code.
Totally blank what I need to fill in 'tmp_name' or 'name' parameters. PHP Code:
|
|
#22
|
|||
|
|||
|
try something like this:
PHP Code:
check if that works and see if you get any output. right now it just dumps the contents of the csv file to the screen so if it is a big file it might be a large screen of data. At the end it shows a count of rows found in the file also. I also confirmed this to work on my windows box. |
|
#23
|
|||
|
|||
|
PHP Code:
this smiley tells you what I'm feeling like. The page is blank whether I give error_reporting(E_ALL) or not. p.s: I checked my php.ini file and error_reporting(E_ALL) is uncommented. Also I have disabled the last else part coz I have that in my page1.php. |
|
#24
|
|||
|
|||
|
I wanted you to just try that page by itself as it is simply to see if it is working at all as that script is confirmed working on my computer. That would also let us see how far you were able to get on the page. as in "I could see the form, but nothing after submitting it". I've added a few other things just to see how far you get in the page. should help.
PHP Code:
|
|
#25
|
|||
|
|||
|
Hey,
It worked when I executed the code. The output for the sample csv file uploaded: Code:
$_FILES array found.
Move uploaded file worked.
File found in script directory.
Array
(
[0] => Data for field 1
[1] => some data for field 2
[2] => and a bit of data for field 3
)
Array
(
[0] => Just some test stuff
[1] => Mary had a little lamb
[2] => roses are red
)
Array
(
[0] => violets are blue
[1] => blah blah blah
[2] => and final field
)
3 rows were found.
My sample csv file: Code:
Data for field 1, some data for field 2, and a bit of data for field 3 Just some test stuff, Mary had a little lamb, roses are red violets are blue, blah blah blah, and final field |
|
#26
|
|||
|
|||
|
well if that worked then there is nothing wrong with your server. It is a code problem. Probably the form that submits to that page has something wrong. Double check the case in the form because PHP is case sensitive for things like field names and if needed just copy/paste the form from my code into the other page and add any other fields you need.
|
|
#27
|
|||
|
|||
|
Hey,
I checked the code and made it work. The problem was I didn't give name attribute in the html form for continue submit button. Once I gave the name attribute, and called in 2nd page using post option it did the job. Now I'm trying to add checkbox dynamically to this existing table I echo out. Where I want to delete a particular row or select all rows in the table using Javascript. Probably, I'll be posting the code in client-side things coz I need help to figure out a small thing. Thank you! |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Parse a csv file and then store it in db |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|