我正在为图像构建一个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”开始后立即运行测试回声,但它甚至都不会运行它。
答案 0 :(得分:0)
你错过了(
:
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