problem with fopen and the file size.
Author |
Message |
Pyre #1 / 6
|
 problem with fopen and the file size.
Hi, I'm using Apache and PHP under NT. I try to import data from a text file using fopen but I only get the beginning of the data. My file is 2.3Mb big. Is there any parameter in php.ini that I have to set to get it work? Thanks a lot.
|
Tue, 26 Apr 2005 18:50:51 GMT |
|
 |
Jon Kraf #2 / 6
|
 problem with fopen and the file size.
Quote:
> I'm using Apache and PHP under NT. > I try to import data from a text file using fopen but I only get the > beginning of the data. My file is 2.3Mb big. > Is there any parameter in php.ini that I have to set to get it work?
Hi Pyrex, Is it a local or remote file? How much data do you get? Is there an error message? Is the amount of bytes to read for fgets() sufficient? JOn
|
Tue, 26 Apr 2005 20:26:47 GMT |
|
 |
Wolfgang Pichle #3 / 6
|
 problem with fopen and the file size.
hi, show us your sourcecode what have you used after fopen ? fread or fgets ? look in the manual for the difference -> probably this is your problem. Which system are your running ? Have you opend the file in the mode "b". Is it a text or binary file ? mfG Wolfi Quote: > Hi, > I'm using Apache and PHP under NT. > I try to import data from a text file using fopen but I only get the > beginning of the data. My file is 2.3Mb big. > Is there any parameter in php.ini that I have to set to get it work? > Thanks a lot.
|
Tue, 26 Apr 2005 21:46:39 GMT |
|
 |
Pyre #4 / 6
|
 problem with fopen and the file size.
Hi all, I get through this in using file() function. My text file is on a network drive and it works well now. I still don't know why fopen didn't get all my file!!! :-( In the other hand File() was much better for what I wanted to do..... Anyway here is my code (I let the Mysql part, it could help): $fichier = "E:\\AN_PIK\\PREISE\\RMP_o_PI.TXT"; $fp = file($fichier); $nb = count($fp); print $nb; for ($i=0 ;$i < $nb;$i++){ connect_MySQL(); select_db(); $list = explode( "\t",$fp[$i]); if (ereg("'",$list[1])) $list[1] = str_replace ("'","\'",$list[1]); $col0= $list[0]; $col1 = $list[1]; $col2= $list[3]; $col3= $list[4]; $col4 = $list[5]; $col5 = $list[6]; $col6 = $list[7]; $col7 = $list[8]; $query = "INSERT INTO SAP_file(col0,col1,col2,col3,col4,col5,col6,col7) VALUES('$col0','$col1','$col2','$col3','$col4','$col5','$col6','$col7')"; $result= MYSQL_QUERY($query); if(mysql_error()) { print "Error: ".mysql_error(); exit(); } } Thanks a lot for responding and trying to help me....
Quote:
> hi, > show us your sourcecode > what have you used after fopen ? fread or fgets ?
The both gave the same part of my file... Quote: > the difference -> probably this is your problem. Which system are your > running ? Have you opend the file in the mode "b". Is it a text or > binary file ? > mfG > Wolfi > > Hi, > > I'm using Apache and PHP under NT. > > I try to import data from a text file using fopen but I only get the > > beginning of the data. My file is 2.3Mb big. > > Is there any parameter in php.ini that I have to set to get it work? > > Thanks a lot.
|
Tue, 26 Apr 2005 22:18:37 GMT |
|
 |
Nikolai Chuvakh #5 / 6
|
 problem with fopen and the file size.
Quote: > Anyway here is my code (I let the Mysql part, it could help): > $fichier = "E:\\AN_PIK\\PREISE\\RMP_o_PI.TXT"; > $fp = file($fichier); > $nb = count($fp); > print $nb; > for ($i=0 ;$i < $nb;$i++){ > connect_MySQL(); > select_db(); > $list = explode( "\t",$fp[$i]); > if (ereg("'",$list[1])) > $list[1] = str_replace ("'","\'",$list[1]); > $col0= $list[0]; > $col1 = $list[1]; > $col2= $list[3]; > $col3= $list[4]; > $col4 = $list[5]; > $col5 = $list[6]; > $col6 = $list[7]; > $col7 = $list[8]; > $query = "INSERT INTO > SAP_file(col0,col1,col2,col3,col4,col5,col6,col7) > VALUES('$col0','$col1','$col2','$col3','$col4','$col5','$col6','$col7')"; > $result= MYSQL_QUERY($query); > if(mysql_error()) > { > print "Error: ".mysql_error(); > exit(); > } > }
Looks like all of the above could be done by simply loading the source file directly into MySQL. Something like this: $fichier = "E:\\AN_PIK\\PREISE\\RMP_o_PI.TXT"; $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") or die("Could not connect"); mysql_select_db("my_database") or die("Could not select database"); $query = "LOAD DATA INFILE '$fichier' ". "INTO TABLE SAP_file ". "FIELDS TERMINATED BY '\t' ". "LINES TERMINATED BY '\r\n' ". "(col0, col1, col2, col3, col4, col5, col6, col7) "; $result = mysql_query($query) or die("Query failed"); Cheers, NC
|
Wed, 27 Apr 2005 04:12:41 GMT |
|
 |
Pyre #6 / 6
|
 problem with fopen and the file size.
I tried LOAD DATA INFILE several times and it didn't work, I don't know why, so I improvised this ugly code which works pretty good anyway... Thanks for your suggestion.
Quote:
> > Anyway here is my code (I let the Mysql part, it could help): > > $fichier = "E:\\AN_PIK\\PREISE\\RMP_o_PI.TXT"; > > $fp = file($fichier); > > $nb = count($fp); > > print $nb; > > for ($i=0 ;$i < $nb;$i++){ > > connect_MySQL(); > > select_db(); > > $list = explode( "\t",$fp[$i]); > > if (ereg("'",$list[1])) > > $list[1] = str_replace ("'","\'",$list[1]); > > $col0= $list[0]; > > $col1 = $list[1]; > > $col2= $list[3]; > > $col3= $list[4]; > > $col4 = $list[5]; > > $col5 = $list[6]; > > $col6 = $list[7]; > > $col7 = $list[8]; > > $query = "INSERT INTO > > SAP_file(col0,col1,col2,col3,col4,col5,col6,col7)
VALUES('$col0','$col1','$col2','$col3','$col4','$col5','$col6','$col7')"; Quote: > > $result= MYSQL_QUERY($query); > > if(mysql_error()) > > { > > print "Error: ".mysql_error(); > > exit(); > > } > > } > Looks like all of the above could be done by simply loading > the source file directly into MySQL. Something like this: > $fichier = "E:\\AN_PIK\\PREISE\\RMP_o_PI.TXT"; > $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") > or die("Could not connect"); > mysql_select_db("my_database") > or die("Could not select database"); > $query = "LOAD DATA INFILE '$fichier' ". > "INTO TABLE SAP_file ". > "FIELDS TERMINATED BY '\t' ". > "LINES TERMINATED BY '\r\n' ". > "(col0, col1, col2, col3, col4, col5, col6, col7) "; > $result = mysql_query($query) > or die("Query failed"); > Cheers, > NC
|
Fri, 29 Apr 2005 17:19:04 GMT |
|
|
|