Display The Content Of The File In The Browser Window

Discussion in 'PHP' started by kumar84, Jul 13, 2007.

  1. #1
    hai friends

    Iam having a file named as demo.txt , now i want to insert this file in the mysql database and then i want to retrieve the content of the demo file and i want to display it in the browser

    can any body GIVE THE PHP CODE FOR THIS

    THANK U IN ADVANCE
     
    kumar84, Jul 13, 2007 IP
  2. Im The ONE

    Im The ONE Peon

    Messages:
    800
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    //let $abc be the variable to store data from the file and function file_get_contents is used to extract data in file 
    $abc = file_get_contents("demo.txt");
    //then your mysql query, let content be the table and demo the field
    mysql_query("UPDATE content SET demo='$abc' where id='$id'") or die(mysql_error());
    //here's the fetching part doing it the mysql_fetch_array method
    $sql = mysql_query("SELECT * FROM content WHERE id='$id'");
    $row=mysql_fetch_array($sql);
    $anything=$row['fieldname'];
    //demo now stores the data of $abc that was stored earlier
    $demo=$row['demo']
    
    PHP:
     
    Im The ONE, Jul 13, 2007 IP
  3. Cloudberries

    Cloudberries Peon

    Messages:
    74
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I can't really see any need for a database here - all you would really need to do, to display the contents of a specific file in the browser window, is use the following code (place demo.txt in a directory named "text_files" in the directory of the php script for this to work...)

    
    readfile("text_files/demo.txt");
    
    PHP:
    Easy as :)

    (although if you do actually need to have the contents in the database too, the code posted before mine would work just fine!)
     
    Cloudberries, Jul 13, 2007 IP