problem with fopen and the file size. 
Author Message
 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  
 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  
 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  
 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  
 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  
 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')";

- Show quoted text -

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  
 
 [ 6 post ] 

 Relevant Pages 

1. Using $fopen to write to variable files

2. URGENT : Problems with FOPEN(), FSEEK(), FREAD() ...

3. problems with fopen

4. PHP fopen and fsockopen problem

5. File Size, Volume Size

6. Problem with over-size _ru or _rd files

7. How can I know the .EXE file name, file date, file size

8. foxw2600.esl file size problem

9. 2gig file size problem - help!

10. Cosmoplayer and file size problems

11. File size problems

12. File size if giving big problem.

 

 
Powered by phpBB® Forum Software