View Full Version : PHP File -> DB field
pavmoxo
05-13-2006, 09:50 AM
I have the next code to convert php for txt:
<?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($FileOpen, 8192);
}
//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?
Do you want to put in the source or the output of the PHP file?
What sort of database are we talking here?
pavmoxo
05-13-2006, 11:12 AM
I want to put the html code converted of the PHP file
The database is mysql
<?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.");
?>
pavmoxo
05-16-2006, 09:51 AM
At this moment I have:
$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??
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.
pavmoxo
05-16-2006, 10:21 AM
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??
the script that insert the text in DB is in /adminAt http://10.0.0.9/admin/?
pavmoxo
05-16-2006, 11:04 AM
File to open:
newsletter/newstotxt.php
Script
admin/phptoDB.php
Then it would be ../newsletter/newstotext.php.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.