Results 1 to 18 of 18

Thread: File system

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    File system

    Hi alll

    I am handling large no file. I would like to read all those file content and would like to extract some line from file. Is there any body help me out. I would like to get code or some logic that i write code myself.


    Thanks
    Ramesh

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: File system

    Hi RameshChaudhary

    The principal is quite simple... you can read a whole file's contents like so:

    PHP Code:
    $fileContents implode(''file('http://www.someplace.com/filename.xyz')); 
    This will assign the contents of the file too the variable $fileContents.

    Optionally though you could just do this:

    PHP Code:
    $fileContents file('http://www.someplace.com/filename.xyz'); 
    That would generate an array, each element of the array representing one line of the file - you could loop through those to find the required lines and use them.

    -- Ryan Jones
    My Blog.

    Ryan Jones.

  3. #3

    Re: File system

    This is a usefull bit. Thanks!

  4. #4

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    Thanks for your TIPs, Could you tell me how do i read specific line number or text on a file.













    Quote Originally Posted by sciguyryan
    Hi RameshChaudhary

    The principal is quite simple... you can read a whole file's contents like so:

    PHP Code:
    $fileContents implode(''file('http://www.someplace.com/filename.xyz')); 
    This will assign the contents of the file too the variable $fileContents.

    Optionally though you could just do this:

    PHP Code:
    $fileContents file('http://www.someplace.com/filename.xyz'); 
    That would generate an array, each element of the array representing one line of the file - you could loop through those to find the required lines and use them.

    -- Ryan Jones

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: File system

    Well each index in the array will correspond to the line number, such that:
    PHP Code:
    $fileContents file('http://www.someplace.com/filename.xyz');  

    // line 1
    $line1 $fileContents[0];

    // line 2
    $line2 $fileContents[1]; 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    Thanks visualAd ,


    Ramesh

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: File system

    Unless you have any further questions please go to the "Thread Tools" menu above the first post and click "Mark Thread Resolved". This will let other forum users know your question has been answered. Thanks!

  8. #8

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    Quote Originally Posted by visualAd
    Well each index in the array will correspond to the line number, such that:
    PHP Code:
    $fileContents file('http://www.someplace.com/filename.xyz');  

    // line 1
    $line1 $fileContents[0];

    // line 2
    $line2 $fileContents[1]; 
    Hi VisualAD,

    I have code below and it diplays contents of 'C:/zipunzip/unzip/prifiles/0006509972022089.pri' file. But i would like to view contetns of all files in 'C:/zipunzip/unzip/prifiles/

    --------------------------------------------------------------------------
    $lines = file('C:/zipunzip/unzip/prifiles/0006509972022089.pri');

    foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";

    }

    echo "</br>";
    // line 1

    $line1 = $lines[0];
    $line2 = $lines[1];
    $line3 = $lines[2];
    $line4 = $lines[3];
    $line5 = $lines[4];
    $line6 = $lines[5];
    $line7 = $lines[6];
    $line8 = $lines[7];
    $line9 = $lines[8];
    $line10 = $lines[9];
    $line11 = $lines[10];
    $line12 = $lines[11];
    $line13 = $lines[12];
    $line14 = $lines[13];
    $line15 = $lines[14];
    $line16 = $lines[15];
    $line17 = $lines[16];
    $line18 = $lines[17];
    ---------------------------------------------------------------------
    Thanks
    Ramesh

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: File system

    What on earth are you trying to do here?
    Code:
    $line1 = $lines[0];
    $line2 = $lines[1];
    $line3 = $lines[2];
    $line4 = $lines[3];
    $line5 = $lines[4];
    $line6 = $lines[5];
    $line7 = $lines[6];
    $line8 = $lines[7];
    $line9 = $lines[8];
    $line10 = $lines[9];
    $line11 = $lines[10];
    $line12 = $lines[11];
    $line13 = $lines[12];
    $line14 = $lines[13];
    $line15 = $lines[14];
    $line16 = $lines[15];
    $line17 = $lines[16];
    $line18 = $lines[17];


    You need to use opendir() and readdir() to find all the files in a given directory.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: File system

    z0mg. Don't copy them all to separate variables like that, it's pointless

    If you want to view contents of all files in a folder you will have to loop through the files one by one and you can do that using scandir(). If you are using PHP 4 the alternative method of getting the filenames are also shown on the page a bit further down.

  11. #11

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    thanks

  12. #12

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    I would like loop contents of all files of directroy.

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: File system

    That's nice for you.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: File system

    Take a look at the PHP manual for the functions that allow you to manipulate directories.

    http://uk2.php.net/manual/en/ref.dir.php

  15. #15

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    Quote Originally Posted by visualAd
    That's nice for you.
    could you tell me that how can i search string in a file.

  16. #16
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: File system

    Quote Originally Posted by RameshChaudhary
    could you tell me that how can i search string in a file.
    since you have your file read into an array $fileContents, simply loop through the array and check for your string.

    ex.
    PHP Code:
    $search_string "my string within quotes";
    for(
    $i=0;$i<=sizeof($fileContents);$i++){
    //define your search term variable
    $search_term $fileContents[$i];

    //check to see if this is your search string
    if($search_term == $search_string){

     
    // do your stuff
    }


    i hope this helps
    Last edited by modpluz; Jul 21st, 2006 at 06:47 AM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  17. #17

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Re: File system

    Thanks, modpluz

    I have large number of files (*.j31) in directory. I would like to rename all files in 5099709047725.jpg. The file name comes after data processing. Want some logic to rename all files in a directory

    thanks
    Last edited by RameshChaudhary; Jul 23rd, 2006 at 04:12 AM.

  18. #18
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: File system

    You need to copy the file using copy() and then delete it using unlink().

Posting Permissions

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



Click Here to Expand Forum to Full Width