我已经编写了一个脚本,除了文件的实际上传之外,一切似乎都很好。这是我拥有的php代码:
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["avatar"]["name"]));
if ((($_FILES["avatar"]["type"] == "image/gif")
|| ($_FILES["avatar"]["type"] == "image/jpeg")
|| ($_FILES["avatar"]["type"] == "image/jpg")
|| ($_FILES["avatar"]["type"] == "image/pjpeg")
|| ($_FILES["avatar"]["type"] == "image/x-png")
|| ($_FILES["avatar"]["type"] == "image/png"))
&& ($_FILES["avatar"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["avatar"]["error"] > 0)
{
header("Location: ../../dashboard.php?page=profile&error=true");
}
else
{
$newfilename = "uwhduwhd";
$path = "../../avatar/";
move_uploaded_file($_FILES["avatar"]["tmp_name"],"$path" . $newfilename);
header("Location: ../../dashboard.php?page=profile&error=false");
}
}
else
{
header("Location: ../../dashboard.php?page=profile&error=true");
}
?>
我还想做的是将 $newfilename 作为通过上一页上的表单传递的 ID,使用
有人可以帮忙吗?谢谢