PHP图片上传脚本无法运行
我正在为图像构建一个 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”开始后立即运行测试回显,但它甚至不会运行它。
I'm building a php upload script for images, and it refuses to run at all.
First off, I've got a simple post form like this:
<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>
This then feeds the submitted fields to "variables.php", which looks like this:
<?php
require("myfunctions.php");
$title = $_POST['name'];
$description =$_POST['description'];
$img = $_FILES["file"];
imgput($img);
generator($title, $description);
?>
"imgput" and "generator" are functions from "myfunctions.php", but the problem isn't in "genrator", so here's what "myfunctions.php" looks like:
<?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";
}
}
?>
Any help would be great. I tried running test echos right after "imgput" begins, but it won't even run it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在这里缺少
(
:很可能您想要这样:
如果您打开了 error_reporting,您会看到语法错误:
You're missing a
(
here:Most likely you wanted this:
If you had error_reporting turned on, you'd have seen the syntax error: