$ _FILES没有返回任何值

时间:2014-06-08 11:13:41

标签: php html

我正在尝试上传文件,但$_FILES变量未从表单返回任何值。 顶部代码是HTML表单,它接受文件,底部代码是表单重定向的文件。

当我尝试打印时,$_FILES的json编码值显示为空。

HTML code:

<form id='text' action ='http://getlegal.in/registration-details/' method = 'POST' enctype='multipart/form-data'>
    <input type='hidden' name='MAX_FILE_SIZE' value='12412412' /> 
    <label for='file'>Profile Pic :</label>

    <input type='file' name='file' id='file' required='required'><br>

    <Input type='submit' name='option' value='Submit'>
</form>

PHP代码:

$allowedExts = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
//echo "yaba daba doo ";
//echo json_encode($temp);
echo json_encode($_FILES);
echo $_FILES['file']['name'];
die();
if (
$_FILES["file"]["type"] == "image/jpeg"
|| $_FILES["file"]["type"] == "image/jpg"
|| $_FILES["file"]["type"] == "image/pjpeg"
|| $_FILES["file"]["type"] == "image/x-png"
|| $_FILES["file"]["type"] == "image/png"
&&($_FILES["file"]["size"] < 500000000 )
&& in_array($extension, $allowedExts)) 
{
    if ($_FILES["file"]["error"] > 0) 
    {
            echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"];
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
        if (file_exists("upload/" . $_FILES["file"]["name"])) 
        {
                echo $_FILES["file"]["name"] . " already exists. ";
        }
        else 
        {
                 move_uploaded_file($_FILES["file"]["tmp_name"],
                 "upload/" . $_FILES["file"]["name"]);
                 echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
            }
    }
} else {
  echo "Invalid file<br>";
  echo "Please uplaoad a valid file. Chech the file type(jpg, png, jpeg) and the size (500kb)";


  echo $_FILES["file"]["name"];
  echo $_FILES["file"]["size"];
  die ();

1 个答案:

答案 0 :(得分:0)

TRY:

$out = array_values($FILES);
json_encode($out);