dqvrlgi3247
2017-07-30 20:19
浏览 60
已采纳

PHP表单似乎将操作更改为其他脚本

I'm building a website that has a form that allows users to upload files, but the form seems to be going to the wrong place. I told it to go to "upload.php", but instead it tries to go to "“upload.php", which I did not include in the form action. It doesn't look like I added any unicode characters in the script. Any reason why this might be happening?

Here's my form in index.html: https://pastebin.com/7PETk5Sy

<!DOCTYPE html>
<html>
<head>
  <title>Deeper</title>
  <link type="text/css" rel="stylesheet" href="style.css"/>
</head>
<body>
  <div id="titlebar">
  <img src="DeeperNetIcon.jpg"></img>
  <h1>DeeperNet</h1>
  <a href="http://oriondark7.com/deeper">Back to Deeper Homepage</a>
  <br/><br/>
  <form action="view.php" method="post">Search for World by ID: <input type="text" name="world">  <input type="submit" value="Search"></form>
  <br/>
  </div>
  <p color="white">Welcome to DeeperNet!</p>
  <div id="upload">
    <h1>Upload World to DeeperNet</h1>
    <form action=“upload.php” method="post" enctype="multipart/form-data">
    World File:
    <br/><br/>
    <input type="file" name="world">
    <br/><br/>
    World Name:
    <br/>
    <input type="text" name="name">
    <br/>
    Description:
    <br/>
    <input type="textbox" name="desc">
    <br/><br/>
    <input type="submit" value="Upload World">
    </form>
    <br/>
  </div>

</body>

The index.html File has 2 Forms, the second form is the one I'm talking about.

Here's my upload.php Script: https://pastebin.com/0FyuAX3Q

<?php
include("index.html");
if(!empty($_POST)) {
    if(isset($_FILES["world"])) {

        $world = $_FILES["world"];

        $name = $world["name"];
        $tmp_name = $world["tmp_name"];
        $size = $world["size"];
        $ext = explode('.', $name);
        $ext = strtolower(end($ext));

        $allowed = "deep";

        if ($ext == $allowed) {
            if ($size <= 300000) {
                $id = uniqid('', true);
                $destination = 'worlds/' . $id . '.' . $ext;
                if(move_uploaded_file($tmp_name, $destination)) {
                    echo '<br/>World: "' . $name . '" uploaded to DeeperNet!';
                    echo “<br/>World ID: ” . $id;
                    $info = fopen('worlds/' . $id . '.txt', 'w');
                    fwrite($info, $_POST['name'] . "
");
                    fwrite($info, $_POST['desc']);
                    fclose($info);
                }
            }
        }

MAMP says I'm using PHP 7.0.8 if you're wondering.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucha4054 2017-07-30 20:21
    已采纳

    Replace your code with this as form accepts this double quotes (") not this one (“)

    <form action="upload.php" method="post" enctype="multipart/form-data">
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题