这些是我用来上传文件的代码。在Xammp窗口中一切工作正常。但是它不能在centos服务器下工作。它抛出错误"Invalid file"。
upload.php
<?php
$allowedExts = array("json");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/json"))
&& ($_FILES["file"]["size"] < 20000) && in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$dir="uploads";
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
unlink("uploads/$entry");
}
}
closedir($handle);
}
move_uploaded_file($_FILES["file"]["tmp_name"],
$f="uploads/" . $_FILES["file"]["name"]);
chmod($f, 0777);
echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
header("Location: user.php");
}
}
}
else
{
echo "Invalid file";
}
?>