当我尝试在 PHP 中上传文件时,它不会让我。在到处转储变量之后,我得到了这个:
Invalid file!
!
NULL
24M
32MNULL
这来自于:
echo "Invalid file!"; //So, we screwed up...
echo "<br />" . $ext . "!<br />";
echo var_dump($_FILES['fileupl']);
echo "<br />" . ini_get('upload_max_filesize');
echo "<br />" . ini_get('post_max_size');
echo "<br />" . var_dump($_FILES['error']);
我上传的任何文件都会返回。
我正在尝试上传任何文件:.zip、.jar、.png,用于一个小的 minecraft 文件共享平台。
变量:
$title = $_POST['title'];
$desc = $_POST['desc'];
$type = $_GET['type'];
//File stuff
$name = $_FILES['fileupl']['name'];
$rname = $_FILES['fileupl']['tmp_name'];
$ftype = $_FILES['fileupl']['type'];
$size = $_FILES['fileupl']['size'];
$ext = strrchr($rname, '.');
$allowedExtensions = array(".zip", ".jar", ".png");
代码:
if (!in_array(end(explode(".",
strtolower($name))),
$allowedExtensions)) {
echo "Invalid file!"; //dafuq, how'd you screw that up man?
echo "<br />" . $ext . "!<br />";
echo var_dump($_FILES['fileupl']);
echo "<br />" . ini_get('upload_max_filesize');
echo "<br />" . ini_get('post_max_size');
echo "<br />" . var_dump($_FILES['error']);
}
else
{
$uploaddir = './content/';
//Begin file shizzle
if (is_uploaded_file($_FILES['fileupl']['tmp_name'])) //Is the file uploaded?
{
$uploadfile = $uploaddir . basename($name);
echo $name . " Uploaded successfully.";
if (move_uploaded_file($rname, $uploadfile))
{
echo $name . " (" . display_filesize($size) . ") Successfully uploaded!";
$q = mysql_query("INSERT INTO `content`(`type`, `creator`, `title`, `description`, `filename`) VALUES('" . mysql_real_escape_string($type) . "', '" . $username . "', '" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($desc) . "', 'Anon')");
if (!$q)
{
echo "mySQL execution failed!";
}
else
{
echo "Uploaded to database!";
}
}
else
{
echo "File could not be moved!";
}
}
else
{
echo "File could not be uploaded!";
echo var_dump($_FILES['fileupl']);
echo "<br />" . ini_get('upload_max_filesize');
echo "<br />" . ini_get('post_max_size');
}
}
我几乎尝试了所有方法,如果有人知道发生了什么,我将不胜感激。
谢谢!