I am trying to create a sites for uploading where i encounter some weird problems. I still remember php does allow a hidden field, MAX_FILE_SIZE to check for files size. However, when i put it inside the upload form, the script seems to be able to upload certain files but not all. After i remove the hidden field. Everything is fine. Could someone advise me on this? Thanks.
MY SCRIPT:
<form action="testing2.php" method="post" enctype="multipart/form-data" name="form1">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<input name="userfile" type="file" id="userfile">
<input type="submit" name="Submit" value="upload">
</form>
<?php
if (ISSET($POST["Submit"]))
{
$temp_name=$FILES['userfile']['tmp_name'];
$size=$FILES['userfile']['size'];
$type=$FILES['userfile']['type'];
if ($temp_name=="")
{
$correct_format=0;
print("<font color=\"#3366FF\" size=\"3\" face=\"Tahoma\">Error: No file uploaded</font><BR>");
}
if (($temp_name!="") AND ($size==0))
{
$correct_format=0;
print("<font color=\"#3366FF\" size=\"3\" face=\"Tahoma\">Error: File size ie 0<font color=\"#3366FF\" size=\"3\"
face=\"Tahoma\"><BR>");
}
if ($FILES['userfile']['size']!=0)
{
print("type:");
print($FILES['userfile']['type']);
if ($FILES['userfile']['type']=="image/gif")
$correct_format=1;
elseif ($FILES['userfile']['type']=="image/pjpeg")
$correct_format=1;
elseif ($FILES['userfile']['type']=="image/jpeg")
$correct_format=1;
elseif ($FILES['userfile']['type']=="image/tiff")
$correct_format=1;
elseif ($FILES['userfile']['type']=="image/bmp")
$correct_format=1;
elseif ($FILES['userfile']['type']=="application/pdf")
$correct_format=1;
elseif ($FILES['userfile']['type']=="application/zip")
$correct_format=1;
elseif ($FILES['userfile']['type']=="application/x-zip-compressed")
$correct_format=1;
elseif ($FILES['userfile']['type']=="application/msword")
$correct_format=1;
elseif ($FILES['userfile']['type']=="application/postscript")
$correct_format=1;
else
{
$correct_format=0;
print("<font color=\"#3366FF\" size=\"3\" face=\"Tahoma\">Invalid file format</font><BR>");
}
}
}
?>