tripwater
11-11-2003, 12:47 PM
I am having a problem with uploading files over a few Megs. I have the MAX_FILE_SIZE set to 20000000 (20 megs) but I can't upload a 10 meg file. At first I thought it was .exe files or binary files causing the problem but I ruled that out.
When I echo the $HTTP_POST_FILES["userfile"]["size"] it shows the correct amount ONLY if the file size is small and the upload was successful. Otherwise it is empty.
Here is my code on the upload page:
$value = "<SCRIPT LANGUAGE=\"JavaScript\">
function TheFormCheck()
{
if (document.emailup.userfile.value == \"\")
{
alert(\"Please select a file to upload to continue.\");
document.file.userfile.focus();
return false;
}
</script>
<body>
<form name=\"file\" method=\"post\" enctype=\"multipart/form-data\" action=\"../admin/fileuploadsubmit.php\" onSubmit=\"return TheFormCheck()\">
<table border=0 cellpadding=3 cellspacing=5 width=100%>
<tr>
<td>
<b>Attach(upload) a file to this issue below</b>
<input type=hidden name=id value=\"".$_GET["dpid"]."\">
</td>
</tr>
<tr>
<td>
<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"20000000\">
Upload this file : <INPUT TYPE=\"file\" name=\"userfile\">
<INPUT TYPE=\"submit\" name=\"load\" value=\"Upload\"><br><br>
</td>
</tr>
</table>
</form>
</body>
</html>";
echo $value;
Here is my submit page code:
if ($HTTP_POST_FILES["userfile"] == "none")
{
echo "<body>
Problem : no file uploaded.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
exit;
}
if ($HTTP_POST_FILES["userfile"]["size"] == 0)
{
echo "<body>
Problem : File size too large. Cannot exceed ".$HTTP_POST_VARS["MAX_FILE_SIZE"]." bytes<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
exit;
}
$path = "../attachments/".$HTTP_POST_VARS["id"];
if (!is_dir($path))
mkdir($path,0700);
$upfile = "../folder/".$HTTP_POST_VARS["id"]."/".$HTTP_POST_FILES['userfile']['name'];
if (!move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $path."/".$HTTP_POST_FILES['userfile']['name']))
{
echo "<body>
Problem : Could not move file into directory.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
exit;
}
else
{
//***************************************************************************************
//********************************file insert**************************************************
$db = db_connect();
//here we insert the file name into our file table
$query = "insert into files values (NULL,".$HTTP_POST_VARS["id"].",'".$HTTP_POST_FILES['userfile']['name']."')";
$result = @mysql_query($query);
if ($result)
{
echo "<body>
File uploaded successfully.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
}
else
{
echo "There was a problem adding the file to the table.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>";
}
}
Thank you for any help.
When I echo the $HTTP_POST_FILES["userfile"]["size"] it shows the correct amount ONLY if the file size is small and the upload was successful. Otherwise it is empty.
Here is my code on the upload page:
$value = "<SCRIPT LANGUAGE=\"JavaScript\">
function TheFormCheck()
{
if (document.emailup.userfile.value == \"\")
{
alert(\"Please select a file to upload to continue.\");
document.file.userfile.focus();
return false;
}
</script>
<body>
<form name=\"file\" method=\"post\" enctype=\"multipart/form-data\" action=\"../admin/fileuploadsubmit.php\" onSubmit=\"return TheFormCheck()\">
<table border=0 cellpadding=3 cellspacing=5 width=100%>
<tr>
<td>
<b>Attach(upload) a file to this issue below</b>
<input type=hidden name=id value=\"".$_GET["dpid"]."\">
</td>
</tr>
<tr>
<td>
<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"20000000\">
Upload this file : <INPUT TYPE=\"file\" name=\"userfile\">
<INPUT TYPE=\"submit\" name=\"load\" value=\"Upload\"><br><br>
</td>
</tr>
</table>
</form>
</body>
</html>";
echo $value;
Here is my submit page code:
if ($HTTP_POST_FILES["userfile"] == "none")
{
echo "<body>
Problem : no file uploaded.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
exit;
}
if ($HTTP_POST_FILES["userfile"]["size"] == 0)
{
echo "<body>
Problem : File size too large. Cannot exceed ".$HTTP_POST_VARS["MAX_FILE_SIZE"]." bytes<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
exit;
}
$path = "../attachments/".$HTTP_POST_VARS["id"];
if (!is_dir($path))
mkdir($path,0700);
$upfile = "../folder/".$HTTP_POST_VARS["id"]."/".$HTTP_POST_FILES['userfile']['name'];
if (!move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $path."/".$HTTP_POST_FILES['userfile']['name']))
{
echo "<body>
Problem : Could not move file into directory.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
exit;
}
else
{
//***************************************************************************************
//********************************file insert**************************************************
$db = db_connect();
//here we insert the file name into our file table
$query = "insert into files values (NULL,".$HTTP_POST_VARS["id"].",'".$HTTP_POST_FILES['userfile']['name']."')";
$result = @mysql_query($query);
if ($result)
{
echo "<body>
File uploaded successfully.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>
</body>
</html>";
}
else
{
echo "There was a problem adding the file to the table.<p>
<form>
<center>
<INPUT type=\"button\" value=\"Close Window\" onClick=\"window.close()\">
</center></form>";
}
}
Thank you for any help.