1

I,m a total PHP newbie, I learned about arrays yesterday and my boss asked me to write a PHP form, I found one on W3 schools and ended up with

<html>
<body>
    <form action="upload_file.php" method="post" enctype="multipart/form-data">
        <label for="file">Filename:</label>
        <input type="file" name="file" id="file"><br>
        <input type="submit" name="submit" value="Submit">
    </form>
</body>
</html>

<?php 
$allowedEXTs = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end ($temp);
if ((($_FILES["file"] ["type"] == "image/jpeg")
    || ($_FILES ["file"] ["type"] == "image/jpg")
    || ($_FILES ["file"] ["type"] == "image/png"))
    && ($_FILES ["file"] ["size"] < 10240)
    && 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"] ["name"] . "<br>";
        echo "Size: " . $_FILES ["file"] ["size"] / 10240 . " kB<br>";
        echo "Stored in:" . $_FILES ["file"] ["tmp_name"];
    }
    if (file_exists("upload/" . $_FILES["file"]["name"]))
    {
        echo $_FILES ["file"] ["name"] . "already exists.";
    }
    else 
    {
        move_uploaded_files ($_FILES ["file"]["tmp_name"], "upload/" . $_FILES ["file"] ["name"]);
    }
}
else
{
    echo "Invalid file";
}
?>

I basically don't know why this is throwing up "Warning: in_array() expects parameter 2 to be array, null given in" that error, can anyone lend a helping hand?

7
  • in in_array() isn't an array, so you get that error. Commented Oct 11, 2013 at 9:28
  • That worked so far, then this error came up Fatal error: Call to undefined function move_uploaded_files() in Commented Oct 11, 2013 at 9:29
  • That's because the function is move_uploaded_file() Commented Oct 11, 2013 at 9:31
  • I've changed that now and its telling me the file is there, BUT the FTP isn't showing it for some reason? Any ideas? Commented Oct 11, 2013 at 9:42
  • Stored in:/tmp/phphDNNWISL8549 thats where it SAYS it is, but for the life of me I cant find that Commented Oct 11, 2013 at 9:53

3 Answers 3

3
$allowedEXTs = array("jpeg", "jpg", "png");

Declared like this,

&& in_array($extension, $allowedExts))

Called like this,

You have declared it with "EXTs" and calling it as "Exts"... Hence the error.

Sign up to request clarification or add additional context in comments.

Comments

1

You define the array with

 $allowedEXTs = array("jpeg", "jpg", "png");

then call it with

&& in_array($extension, $allowedExts))

Make sure the case is the same every time you call a variable.


Same with this line which should be $_FILES:

echo "Error: " . $_Files["file"] ["error"] . "<br>";

Comments

0

You declare the array with $allowedEXTs, but it is spelled small in the if statement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.