为什么file_put_contents没有创建页面?

时间:2013-12-15 20:26:13

标签: php

我正在编写一些代码来为我网站上的网页生成一些随机网址。我的目的是让人员在创建之后重定向到他们刚刚创建的页面,但是它们被转发到'switch',这是一个php代码,用于根据按下哪个单选按钮来确定要触发的功能。这是我的页面,允许他们“上传”到我的网站:

<html>
<head>
<link rel="stylesheet" type="text/css" href="/style.css">
    <title> 
    Learning Made Easy
    </title>
</head>
<body>

    <?php include_once 'googleanalytics.php'; ?>

<a href="http://terrythetutor.com">
    <div class="banner"> </div>
</a>

<?php include 'menu.php'; ?>

<div class="content">
</br>
</br>
</br>
    <form action="../scripts/switch.php" method="post">
    Title: 
    </br><input type="text" name="Title">
</br>
</br>
</br>
    Summary of the video (including questions used in the video): 
    </br><textarea name="Summary" COLS=60 ROWS=10></textarea>
</br>
</br>
</br>
    URL of the video (Yes, this means you need to upload it to an external website.): 
    </br><input type="text" name="URL">
    </br>
    </br>
    Which course does your video pertain to?</br>
    <input type="radio" name="course" value="intermediate"> Intermediate and below</br>
    <input type="radio" name="course" value="college"> College Algebra</br>
    <input type="radio" name="course" value="precalculus"> PreCalculus</br>
    <input type="radio" name="course" value="trigonometry"> Trigonometry</br>
    <input type="radio" name="course" value="calculus I"> Calculus I</br>
    <input type="radio" name="course" value="calculus II"> Calculus II</br>
    <input type="radio" name="course" value="calculus III"> Calculus III</br>
    <input type="radio" name="course" value="differential equations"> Differential Equations</br>
    </br>
    </br>
    <input type="submit" value="Submit, foo!">
    </form>
</br>
</br>
</br>
<p>
Please understand that you will not be able to change the title, summary, or URL of your video after submission.
</p>


</div>

<div class="footer">
    <?php include 'footer.php'; ?>
</div>


</body>

</html>

这一点很好用。之后,它们被重定向到'switch.php'。你已经知道那是做什么的。

<?php
    if (isset($_POST['course']) && $_POST['course'] == 'intermediate') {
        include('storeintermediate.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'college') {
         include('step2a.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'precalculus') {
        include('replace.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'trigonometry') {
        include('replace.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'calculus I') {
        include('replace.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'calculus II') {
        include('replace.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'calculus III') {
        include('replace.php');
    } elseif (isset($_POST['course']) && $_POST['course'] == 'differential equations') {
        include('replace.php');
      }
 ?>

从那里,我们去storeintermediate.php,在那里我具有抓取所有变量的功能,将它们存储在数据库中,创建一个带有模板格式的新随机生成的页面,并提取视频的URL他们正在上传。

<?php
// Create connection
$con = mysqli_connect("*******","******","************","*");
$IP = $_SERVER['REMOTE_ADDR'];
$IP = mysqli_real_escape_string($con, $IP);
$Title = mysqli_real_escape_string($con, $_POST[Title]);
$Summary = mysqli_real_escape_string($con, $_POST[Summary]);
$URL = mysqli_real_escape_string($con, $_POST[URL]);


$number = mt_rand(100,99999999); // see $new_url

$nospace = str_replace(' ', '_', $Title); // to enable URL friendly titles

$new_url = $number . $nospace ;  // to ensure that each URL is unique

$data = include( '../template.php');

$embed_URL = substr( $URL, -11);

file_put_contents("../videos/" . $new_url, $data, FILE_APPEND) ;


// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

  $sql="INSERT INTO `Intermediate Algebra` (Title, URL, IP, Summary)
VALUES 
('$Title','$URL','$IP','$Summary')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }

header('Location: http://terrythetutor.com/'.$new_url);

?>

现在,我的问题:当我提交测试页面时,页面已创建。但是大小是1个字节,文件中唯一的东西是'1'。我无法理解为什么。

其次,重定向到的页面(也出于某种原因持有提交的内容)是STEP.php,但它确实应该是创建的页面。

第三个(可能与第二个相关),当我尝试重定向到新生成的页面时,我的标题出现错误。

非常感谢任何帮助。非常感谢你,

特里。

1 个答案:

答案 0 :(得分:3)

include("../template.php")的返回值不是您认为的。 include没有返回包含的文件输出,它返回包含的文件返回的内容,如果文件没有&#返回1 39; t在文件范围内包含return语句。