Results 1 to 10 of 10

Thread: PHP File -> DB field

  1. #1
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool PHP File -> DB field

    I have the next code to convert php for txt:



    PHP Code:
    <?php 
        
    if($_POST["phptohtml"] != ""
        { 
            
    // Open a script file 
               
    $File "http://10.0.0.9/cm-lousa.pt/2.0/newsletter/newstotxt.php"
                
               
    //Open the file $File 
               
    $FileOpen fopen($File"r"); 
                
               
    // Init Contain 
               
    $Contain =""
                
               
    //Create the ouptut file (temp.html as example) 
               
    touch("temphtml/news.txt"); 
                
                
               
    //Open the file on "append" mode 
               
    $Add fopen("temphtml/news.txt","a"); 
                
                
                 
               
    //Fill Contain   
               
    while (!feof($FileOpen))  
               { 
                  
    $Contain .= fread($FileOpen8192); 
               } 
                
               
    //Fill temp.html 
               
    fwrite($Add,$Contain); 
                
               
    //Close 
               
    fclose ($FileOpen); 
                
               
    fclose ($Add); 
               

        } 
        
    ?>
    and wan't to put the content of a php file into a DB field!! How can I do this?? It's possible?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Do you want to put in the source or the output of the PHP file?
    What sort of database are we talking here?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I want to put the html code converted of the PHP file
    The database is mysql

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php
      $conn = mysql_connect("host", "username", "password");
      mysql_select_db($conn, "cm-lousa");
      ob_start(); // begin output buffer
      include("newsletter/newstotext.php"); // put output of script into output buffer -- more efficient than using an HTTP connection
      $html = mysql_real_escape_string(ob_get_clean(), $conn); // store the output and delete the buffer
      mysql_query($conn, "insert into table (news) values (\"$html\");") or die("Query error.");
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    At this moment I have:

    PHP Code:
    $conn mysql_connect(SERVER,DBUSER,DBPWD) or die ("Problemas na ligação MySQL");
    mysql_select_db (DB);
    ob_start(); // begin output buffer
    include("http://10.0.0.9/cm-lousa.pt/2.0/newsletter/newstohtml.php"); 
    $html mysql_real_escape_string(ob_get_clean(), $conn); // store the output and delete the buffer
    include("http://10.0.0.9/cm-lousa.pt/2.0/newsletter/newstotxt.php"); 
    $txt mysql_real_escape_string(ob_get_clean(), $conn); // store the output and delete the buffer
    $sql "insert into newsletters values(NULL, 'zamalek', 'too soft', '".$html."', '".$txt."', '1')";
    $query query($sql) or die ("Query failed: " mysql_error() . " Actual query: " $sql); 
    I want to put the output of newstotxt.php in the DB in the var $txt. Why I doesn't obtain the result that I want in this code?? Can You explain to me??

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Because you end the output buffer with ob_get_clean(). You must call ob_start() again before the second include to create a new output buffer.

    You ought to avoid using URLs if the page is on the same server as the requested page, since you are establishing a TCP HTTP connection to localhost, which is pointless and far less efficient than accessing the include by a local path.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    But only with

    include("newsletter/newstotxt.php");

    it can't open the file!!! the script that insert the text in DB is in /admin

    Any suggestion??

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    the script that insert the text in DB is in /admin
    At http://10.0.0.9/admin/?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Apr 2006
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    File to open:
    newsletter/newstotxt.php

    Script
    admin/phptoDB.php

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Then it would be ../newsletter/newstotext.php.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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