Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to open huge file so as to break it up?

    I have a file of about 500,000 records. If I try to open it with file("myfile.txt"), I get a page cant be displayed error. I assume it chokes on size. I want to chop the file into smaller pieces. How can I do this if I cannot even open the file?

    G

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you'd probably want to use fopen, fgets and fclose to read the file a line at a time

    note: you may well need to raise your max_execution_time with an ini_set() call or recall the same script multiple times and adjust the start point with fseek and ftell

    dodgy untested example

    PHP Code:
    $fsk = (isset($_GET['fsk'])) ? $_GET['fsk'] : 0;
    $fp fopen('filename.ext');
    while(
    $f_line fgets($fp4096))
     {
     
    // process the line here
     // adjust the 200000 below to set read size
     
    if(ftell($fp) > ($fsk 200000))
      {
      
    // 200KB processed - refresh page
      
    header("location: ............?fsk=" .ftell($fp));
      }
     } 
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •