繁体   English   中英

PHP图片上传脚本无法运行

[英]PHP image uploading script won't run

我正在为图像构建一个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”中的函数,但问题不在“ generator”中,因此“ 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”开始之后立即运行测试回显,但它甚至无法运行。

您缺少(在这里:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM