Uploading an image using php
<p>I'm trying to upload an image using the script below. When I use the script for uploading alone the image is uploaded to the temporary file but once I add the restrictions on uploading I get an error message "Invalid File". Any ideas?</p>

<pre><code>&lt;?php
//Restrictions on file upload
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
   || ($_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"))
   &amp;&amp; ($_FILES["file"]["size"] &lt; 20000)
   &amp;&amp; in_array($extension, $allowedExts))
{
    //Upload Script
    if ($_FILES["file"]["error"] &gt; 0)
    {
        echo "Error: " . $_FILES["file"]["error"] . "&lt;br&gt;";
    }
    else
    {
        echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;";
        echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br&gt;";
    }
    //Save the uploaded file
    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";
}
</code></pre>

<p>?></p>
