访问页面时使用HTML 505(PHP)

时间:2019-03-09 23:09:35

标签: php

尝试运行PHP页面时出现错误505。这就是说</html>末尾有意外的$ EOF。我已经删除了元素,并将其添加回去。这是我的代码。

<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_FILES["userfile"])) {

$user = $_SESSION['username'];

$dir = "videos/".$user."/";

if(isset($_POST['submit'])){
if (!file_exists($dir)) {

mkdir($dir, 0777, true);
}
move_uploaded_file($_FILES['file']['tmp_name'],"pictures/".$user."/".$_FILES['file']['name']);
}
?>
<html>
 <head>
  <title>File Upload Progress Bar</title>
  <link rel="stylesheet" type="text/css" href="style.css">
 </head>
 <body>
  <div id="bar_blank">
   <div id="bar_color"></div>
 </div>
  <div id="status"></div>
      <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST" 
id="myForm" enctype="multipart/form-data" target="hidden_iframe">
       <input type="hidden" value="myForm"
    name="<?php echo ini_get("session.upload_progress.name"); ?>">
   <input type="file" name="userfile">
   <input type="submit" value="Start Upload">
  </form>
  <iframe id="hidden_iframe" name="hidden_iframe" src="blank.html"> 
   </iframe>
  <script type="text/javascript" src="script.js"></script>
 </body>
</html>

我正在使用PHP 7.0。

1 个答案:

答案 0 :(得分:0)

您尚未关闭所有if条件块。尝试缩进代码,这将指出此类错误

<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_FILES["userfile"])) {

    $user = $_SESSION['username'];

    $dir = "videos/".$user."/";

    if(isset($_POST['submit'])){
       if (!file_exists($dir)) {

          mkdir($dir, 0777, true);
       }
       move_uploaded_file($_FILES['file'] . 
       ['tmp_name'],"pictures/".$user."/".$_FILES['file']['name']);
    }
<< ---- Missing closing ----->>
?>
<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_FILES["userfile"])) {

    $user = $_SESSION['username'];

    $dir = "videos/".$user."/";

    if(isset($_POST['submit'])){
       if (!file_exists($dir)) {

          mkdir($dir, 0777, true);
       }
       move_uploaded_file($_FILES['file'] . 
       ['tmp_name'],"pictures/".$user."/".$_FILES['file']['name']);
    }
}
?>