1

画像用の php アップロード スクリプトを作成していますが、実行をまったく拒否しています。

まず、次のような単純な投稿フォームがあります。

    <form action="variables.php" method="post" enctype="multipart/form-data" >  
  <p>Event title : <input type="text" name="name" required></p>
  <p>Description : <input type="text" name="description" required></p>
  <input type="file" name="file" id="file"/>
  <input type="submit" value="submit">
    </form>

次に、送信されたフィールドを「variables.php」にフィードします。これは次のようになります。

  <?php
 require("myfunctions.php");

 $title = $_POST['name'];
 $description =$_POST['description']; 
  $img = $_FILES["file"];

 imgput($img);
 generator($title, $description);
     ?>

「imgput」と「generator」は「myfunctions.php」の関数ですが、「genrator」には問題がないので、「myfunctions.php」は次のようになります。

    <?php
function imgput($img) { 
 if ((($img["type"] == "image/gif")
 || ($img["type"] == "image/jpeg")
 || ($img["type"] == "image/pjpeg"))
  && ($img["size"] < 500000))
   {
   if ($img["error"] > 0)
     {
     echo "Return Code: " . $img["error"] . "<br />";
     }
   else
     {
     echo "Upload: " .$img["name"] . "<br />";
     echo "Type: " . $img["type"] . "<br />";
     echo "Size: " . $img["size"] / 1024) . " Kb<br />";
     echo "Temp file: " . $img["tmp_name"] . "<br />";

     if (file_exists("../uploads/" . $img["name"]))
       {
       echo $img["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($img["tmp_name"],
       "../uploads/" . "event1.jpg");
       echo "Stored in: " . "../uploads/event1.jpg";
       }
     }
   }
 else
   {
   echo "Invalid file";
   }
}

?>

どんな助けでも素晴らしいでしょう。「imgput」が始まった直後にテストエコーを実行しようとしましたが、実行すらしません。

4

1 に答える 1

0

ここに a がありません(:

echo "Size: " . $img["size"] / 1024) . " Kb<br />";
                                  ^^^  no matching ( available

ほとんどの場合、これが必要でした:

echo "Size: " . ($img["size"] / 1024) . " Kb<br />";

error_reporting をオンにすると、次の構文エラーが表示されます。

PHP Parse error:  syntax error, unexpected ')', expecting ',' or ';' in /home/marc/test.php on line 16
于 2010-09-06T23:36:17.503 に答える