Hi, I am trying to write a script that checks the size and type of a file as it is selected, without submitting the form:
<input name=”uploadedfile” type=”file” onchange=”ajax_check_image()”/>
The Ajax function basically looks like this:
//Opens and sends the ajax request
ajax_request.open(“GET”,”functions/check_image_file.php”,true);
ajax_request.send(null);
And then the script it calls looks like this:
<?php
//Checks if the image is the right file type and less than 100k.
if ((($_FILES[“uploadedfile”][“type”] == “image/gif”)
|| ($
|| ($_FILES[“uploadedfile”][“type”] == “image/pjpeg”))
&& ($
{
//If
if ($_FILES[“uploadedfile”][“error”] > 0)
{
echo ($
}
else
{
echo ($_FILES[“uploadedfile”][“name”] . ” is an valid image file”);
}
}
else
{
echo “Invalid file”;
}
?>
The problem is that the PHP $FILES[][] only picks up the files if it has been submitted from a form.
Is there anyway to check the file without submitting the form?
Thanks in advance.