0

私はPHPが初めてで、少し問題があります。

Netbeans 7.3 でコーディングした .php ファイルは、IDE のコンパイラで実行すると正常に動作します。しかし、同じ Web ページを Google Chrome ブラウザーで実行するとそのままのコードが表示されます。

これがサンプルコードです-

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> Add Your Highscore! </title>
    </head>
    <body>
        <h2> Guitar Wars - Add you highscore!</h2>
        <?php
        //echo "successful!!";


        if(isset($_POST['submit'])){
        $name=$_POST['name'];
        $score=$_POST['score'];
        $screenshot=$_FILES['screenshot']['name'];
        $screenshot_type=$_FILES['screenshot']['type'];
        $screenshot_size=$_FILES['screenshot']['size'];

        $output=false;
        if(!empty($name)&&!!empty($score)&&!empty($screenshot))
       {  

            if ((($screenshot_type == 'image/gif') || ($screenshot_type == 'image/jpeg') || ($screenshot_type == 'image/pjpeg') || ($screenshot_type == 'image/png'))
        && ($screenshot_size > 0) && ($screenshot_size <= GW_MAXFILESIZE)) {
        if ($_FILES['screenshot']['error'] == 0) {
          // Move the file to the target upload folder
          $target = 'images' . $screenshot;
          if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) 
            // Connect to the database
         {
            $db=  mysqli_connect('localhost','root', 'akash123','gwdb') 

                  or die('Error in connecting to the database');
        //echo "</br> successful connection";
        $query= "insert into guitar wars values(0,NOW(),$name, $score, $screenshot ";
        //echo "</br> successful query";
        $result= mysqli_query($db,$query) ;

       mysqli_close($db,$query);
       echo "</br> Successful!";
       $name='';
       $score='';
       $screenshot='';

        mysqli_close($db);
        }
        else
        {echo "There was a problem uploading the image";
        }

        }  
        else
        {echo "There was a problem uploading the image";

        $output=true;
        }
        }


        else{echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>';
        $output=true;
        }}

        else{echo "* Enter all the information to add your highscore";
        $output=true;
        }

        }

        else
        { 
            $output=true;
            $name='';
            $score='';
        }

            if ($output){ 
            ?>

<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="hidden" name="MAX_FILE_SIZE" value="65536"/>
<label for="name">Full Name:</label>
<input type="text" id="name"  name="name" value="<?php echo $name ; ?>" /></br>
<label for="score">Your Highscore :</label>
<input type="text" id="score"  name="score" value="<?php echo $score ; ?>" /></br>
<label for="screenshot"> Screenshot of your Highscore: </label>
<input type="file" id="screenshot" name="screenshot" /></br>
<input type="submit" name="submit" value="Add"/>

</form>
    <?php

        }


        ?>
    </body>
</html>

Internet Explorer は、.php ファイルをダウンロードしようとするため、絶望的です。

この結果の理由は何ですか?

4

2 に答える 2

1

Web サーバーがファイルを PHP インタープリターに渡していない可能性があります。ウェブサーバーの設定を確認してください。

于 2013-03-29T13:54:19.520 に答える
1

ブラウザでphpファイルを「開く」ことはできません。「実行」する必要があります。netbeans はファイルを実行します (Java のような方法でコンパイルされないことに注意してください)

ローカル マシンでテストする場合は、php を実行する apache インストールが必要です (たとえばxampp )。

xampp を使用している場合:

xampp フォルダー内の htdocs フォルダーを開きます。

webapp 用の新しいフォルダーを作成します。

そのフォルダにphpファイルを置きます。

Web ブラウザーで、php ページに移動します (アドレス バーに、xampp を実行しているマシンの IP アドレス、または localhost を入力するか、構成した方法で mylocalhostip/mywebapp/myphpfile.php などを入力します。

それならうまくいくはずです

于 2013-03-29T14:10:09.123 に答える