Push正在删除使用fwrite创建的文件

时间:2014-02-02 20:07:56

标签: php mysql openshift

我正在使用表单来创建网页,但每次我执行推送时都会删除这些文件。我知道我需要将文件放在一个用于持久数据的目录中但是A)我不知道什么目录和B)我不知道如何确保我创建并放入数据库的URL可供用户访问他们点击它。这是我的PHP代码,它从表单创建网页。

<?php 
$myContent = $_POST['mycontent'];
$titlestart = '<h1>';
$titlestop = '</h1>';
$title = $_POST['title'];
$appendtitle = 'kb'.$title;
$filename = preg_replace('/( *)/', '', $appendtitle);

$footer = file_get_contents('footer.html');
$myFile = $filename.".html";
$fh = fopen($myFile, 'w');
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = file_get_contents('template.html');
fwrite($fh, $stringData);
fwrite($fh, $titlestart);
fwrite($fh, $title);
fwrite($fh, $titlestop);
fwrite($fh, $myContent);
fwrite($fh, $footer);
fclose($fh);

$dbhost = getenv('OPENSHIFT_MYSQL_DB_HOST');
$dbname = getenv('OPENSHIFT_GEAR_NAME');
$dbuser = getenv('OPENSHIFT_MYSQL_DB_USERNAME');
$dbpass = getenv('OPENSHIFT_MYSQL_DB_PASSWORD');
$topicid = 'NULL';
$title = $_POST['title'];
$description = $_POST['description'];
$url = 'https://research-statusquopro.rhcloud.com/'.$filename.'.html';
$keyword = $_POST['keywords'];
$faq = $_POST['faq'];
$category= $_POST['category'];
$con = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
if (empty($title))
{
}
else
{
mysqli_query($con,"INSERT INTO topics (`topicid` ,`topictitle` ,`topicdescription` ,`url` ,`keyword`,`faq`,`Category`) VALUES ('".$topicid."','".$title."','".$description."','".$url."','".$keyword."','".$faq."',".$category."')");
header ('Location: https://urlofapplication');                                            

}
//mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:2)

Openshift提供了一个持久存储目录,您可以使用$ OPENSHIFT_DATA_DIR环境变量访问该目录。