我正在使用表单创建网页,但每次我执行推送时都会删除这些文件。我知道我需要将文件放在用于持久数据的目录中,但是 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);
?>
最佳答案
Openshift 提供了一个持久存储目录,您可以使用 $OPENSHIFT_DATA_DIR 环境变量来访问该目录。
关于php - Push 正在删除使用 fwrite 创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21515573/