【问题标题】:Recieve Variable From php file Using fopen?使用fopen从php文件接收变量?
【发布时间】:2018-03-20 19:18:37
【问题描述】:

我一直在开发一个博客系统,我希望从外部 php 文件中接收关于帖子标题和内容的信息,这是我的代码:

外部(博文内容)文件:03-20-2018-This-Is-A-Test.php

<?php
$Title = 'This is a test!';
$Date = '03-20-2018';
$Content = 'Blog Post&#39;s content!';
?>

用于查看博客文章的客户端页面:Post Home.php

<?php
$Title = '';
$Date = '';
$Content = '';

$GetDate = $_GET['d'];
$GetTitle = $_GET['t'];

$postPath = "Posts/$GetDate"."-"."$GetTitle.php";

$postFile = fopen($postPath,"rt");
$postContent = fgets($postFile,filesize($postPath));
?>

<!--Some HTML-->

<h2><? echo $Title; ?></2>
<b><? echo $Date; ?></b>
<p><? echo $Content; ?></p>

<!--Some More HTML-->

<? fclose($postFile); ?>

客户页面网址:example.com/Post%20Home.php?d=03-20-2018&t=This-Is-A-Test

重新格式化为:example.com/03-20-2018/This-Is-A-Test


如您所见,我使用 GET 参数来调用我希望从中收集信息的文件。 我曾尝试使用无法开始工作的 fopen。我使用的特定服务器主机也禁止 include

如果有人能够帮助我使其工作,我愿意使用 file_get_contents

注意:我已经确认我的调用 URL 是正确的,并且我的 php 没有错误


所以,我正在尝试使用 fopen 从文件中收集 $Title $Date $Content 的数据; 03-20-2018-This-Is-A-Test.php 并在客户端文件中使用该信息; 发布 Home.php

【问题讨论】:

    标签: php get fopen file-get-contents


    【解决方案1】:

    我能够使用 require() 找到答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      相关资源
      最近更新 更多