我的HTML中的php是让我的页面设置好了吗?

时间:2016-03-28 16:44:47

标签: php html

我试图在我的网站上设置一个上传区域,但是当我加载页面时,一切都没有设置,但是当我在HTML中删除php时它会恢复正常。不知道为什么这样做。任何人都知道如何解决这个问题?

<?php
ob_clean();session_start();

    if (isset($_GET['logout'])){
        session_destroy();  
    }

    if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] == false) {
        header("Location: index.php");
    }

    if(isset($_FILES['UploadFileField'])){
        $allowed = array('jpg','png','jpeg');
        $name = $_FILES["UploadFileField"]["name"];
        $tmp = $_FILES['UploadFileField']['tmp_name'];
        $type = $_FILES['UploadFileField']['type'];
        $newName = "Image Attachment.jpg";
        $types = array('jpg','png','jpeg');
        $ext = pathinfo($name, PATHINFO_EXTENSION);

        if(in_array($ext,$types)){
            move_uploaded_file($tmp, "UPLOADS/$newName");
            echo '<font size="3"><p align="center"><b>UPLOAD SUCCESSFUL: </font><font color="#000000" size="3">Your document has now been uploaded and is ready to send.</b></p></font>';
            $loadingimage = true;
        }

        else {
            if(!$tmp){
                echo '<font size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">No document has been selected.</b></p></font>';
            }

            else {
                echo '<font size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">Uploaded document was an incorrect extension type, please use ".jpg", ".jpeg", or "png" only.</b></p></font>';
            }
        }
    }

    if (isset($_POST['submit'])){
        header( 'Location: Review.php' );
    }

    if (isset($_POST['delete'])){   
        if (file_exists("UPLOADS/Image Attachment.jpg")) {
            echo '<font size="3"><p align="center"><b>DETLEION COMPLETE: </font><font color="#000000" size="3">Image no longer available</b></p></font>';
            unlink('UPLOADS/Image Attachment.jpg');
            $loadingimage = false;
        }

        else{
            echo '<font size="3"><p align="center"><b>DETLEION FAILED: </font><font color="#000000" size="3">No image available for Deletion</b></p></font>';
        }
    }   
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Attach Image</title>

        <link href="CSS/boilerplate.css" rel="stylesheet" type="text/css">
        <link href="CSS/master.css" rel="stylesheet" type="text/css"> 
        <script src="JAVASCRIPT/respond.min.js"></script>
</head>
<body link="black">
    <div class="gridContainer clearfix">
        <div id="borderDiv">
            <div id="navDiv">
                <div id="backNavDiv">   
                    <a href="index.php?logout"><font color="white"><p align="right"><b>&nbsp;&lt;&nbsp;Log Out</b></p></font></a>
                </div>
            </div>

            <div id="headerDiv">
                <p>Attach Image</p>
            </div>                


            <div id="loginBtnDiv">
                <div id="uploadAreaDiv">
                    <form action="AttachImage.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
                    <label for="UploadFileField"></label>
                    <input type="file" name="UploadFileField" id="UploadFileField"/>
                    <input type="submit" name="UploadButton" id="UploadButton" value="Upload"/>
                    </form>     
                </div>

                <form action="AttachImage.php" method="post" enctype="multipart/form-data" name="delete" id="delete">
                    <input id="delete" name="delete" type="submit" value="Delete">
                </form>

                <form action="AttachImage.php" method="post" enctype="multipart/form-data" name="FileForm" id="FileForm">
                    <input id="submit" name="submit" type="submit" value="Next">
                </form>
            </div>

        </div>
    </div>
    <div id="logoDiv">
        <img src="IMAGES/Logo.png">
    </div> 
</body>
</html>

2 个答案:

答案 0 :(得分:1)

你的问题是因为你在身体标签之外回复了一些东西!试试这个:

Nds

答案 1 :(得分:0)

您需要将HTML和PHP分隔到自己的文件中。使用Javascript运行PHP文件,彼此分开,并在需要时调用操作。

以下是一个如何运作的示例

此示例是搜索和填充功能。它不是特定于您的问题,但您应该能够看到逻辑。

在HTML输入字段中使用formFill()调用Javascript函数onkeyup。使用AJAX,Javascript调用单独的文件(在本例中是一个运行数据库查询的PHP文件)并输出您指定的内容(即document.getElementById(x).innerHTML = xmlhttp.responseText;)。

<强> HTML

<input type="text" onkeyup="formFill(this.value, 'lot')" name="lot_number"/>
<div id="lot"></div>

<强>的Javascript

//find & fill forms with onkeyup values 
function formFill(search,x) {
       if (search.length == 0) { 
          document.getElementById(x).innerHTML = "";
          return;
       } else {
          var xmlhttp = new XMLHttpRequest();
          xmlhttp.onreadystatechange = function() {
               if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                   document.getElementById(x).innerHTML = xmlhttp.responseText;
               }
           }
          xmlhttp.open("GET", "/forms/pull/"+ x +".php?q=" + search, true);
          xmlhttp.send();      
         }
     }

<强> PHP     

$s_sql="SELECT lots.lot_number
            FROM lots
            WHERE lots.lot_number LIKE '".$_REQUEST["q"]."%'";

$result = mysqli_query($con,$s_sql);
$s_arr = mysqli_fetch_array($result);

// Output
echo isset($s_arr) === false ? '' : $s_arr[0];
?>

这个PHP查询&#34;显示&#34;数据使用echo,因为整个文件将被执行并显示给用户。