Hi I don't get this it works fine but any file i upload that is over 300kb doesn't get emailed or saved to the server but if i upload two files for example 260kb 290kb they both upload and are both saved to the server. here is what I am using.
Why is this doing this I find this very odd why if 1 file is more than 300kb??

<form name="iapply3" method="post" action="../submit/isubmit.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input type="hidden" name="usename" value="johnny99" />
<table class="form">


<tr><td colspan="2" class="head">PHOTO 1</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>

<tr><td colspan="2" class="head">PHOTO 2</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>

<tr><td colspan="2" class="head">SEND LATER</td></tr>
<tr><td colspan="2" class="selection"><input type="checkbox" name="later" value="Yes" /></td></tr>

<tr><td class="head">&nbsp;</td><td class="head">&nbsp;</td></tr>


<tr><td colspan="2" class="submit" ><input name="submit" type="submit" value="Submit" /></td></tr>
<tr><td colspan="2" class="submit"><input name="reset" type="reset" value="Reset" /></td></tr>

<tr><td class="head">&nbsp;</td><td class="head">&nbsp;</td></tr>

</table>
</form>
</body>
</html>
<? 
session_start();
error_reporting(apa);
error_reporting(7);
include("../secure/global/connection.php");

$username = $_POST["username"];

mkdir("../secure/admin/clients/$username", 0700);

			


        $to = 'info@website.com';
        $subject = "Success";
        $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
        // headers
        $headers .= "From: Website <noreply@websire.com>\n";  
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
        // message
        $message = "--{$boundary}\n";
        $message .= "Content-Type: text/html; charset=iso-8859-1\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= "<html>
<head>
<title>HTML message</title>

</head>
<body>

message here

</body>
</html>";




foreach ($_FILES["fileatt"]["error"] as $key => $error) { 
        if ($error == UPLOAD_ERR_OK) { 
$fileatt = $_FILES['fileatt']['tmp_name'][$key];
$fileatt_type = $_FILES['fileatt']['type'][$key];
$fileatt_name = $_FILES['fileatt']['name'][$key]; 

       
        // attachment

        $fp = fopen($fileatt, 'rb');
        $data = fread($fp, filesize($fileatt));
        fclose($fp);

        $data = chunk_split(base64_encode($data));
        $message .= "\n\n";
        $message .= "--{$boundary}\n";
        $message .= "Content-Type: application/$fileatt_type; name=\"$fileatt_name\"\n";
        $message .= "Content-Transfer-Encoding: base64\n\n";
        $message .= "$data\n\n";

move_uploaded_file($fileatt, "./../secure/admin/clients/$username/$fileatt_name"); 
       
    } 
}


        mail($to, $subject, $message, $headers);
?>

Dani AI

Generated

The behaviour you saw (one file > ~300KB failing while two smaller files upload fine) is almost always a server-side limit rather than a form bug. ’s idea to raise the PHP upload limit solved it for , but it helps to understand the full picture and how to debug/fix it reliably.

Two PHP settings control uploads: a per-file limit and a total-POST limit. Also check available script memory since your code reads attachments into memory and base64 expands them. These directives and how/where they can be changed are documented on the PHP site: upload_max_filesize, post_max_size, and memory_limit. Note that many of these are PHP_INI_PERDIR settings and therefore must be adjusted in php.ini, .htaccess (mod_php), or a per-directory .user.ini—ini_set may not take effect on every host.

Practical steps to diagnose and fix:

  • Drop a small phpinfo() page to see current values and which php.ini is in use (phpinfo() docs).
  • Dump the upload array to see error codes and sizes; map error codes to meanings (file upload errors).
  • If server settings are the issue, change php.ini (or .htaccess/.user.ini as appropriate) and restart the webserver, or ask your host to change them.
  • Check webserver limits (Apache’s LimitRequestBody or nginx’s client_max_body_size) if PHP changes don’t help: LimitRequestBody, client_max_body_size.

Quick debug snippet to use on the server:

<?php
phpinfo();
echo "\n\n<pre>";
print_r($_FILES);
echo "</pre>";

Extra notes: base64 encoding grows attachment size ~33%, and some mail servers impose message-size limits. For large files, store to disk first and stream or link to the file rather than inlining huge base64 email attachments.

Recommended Answers

All 3 Replies

Try placing the following at the top of your php file(s) that process the uploads:

ini_set ('upload_max_filesize','10M');

That should allow the server to accept 10 Megabyte files and is the most common solution for this problem from previous posts of simular/same problems on these forums. Let me know if you need more info.

Glad to see you didn't back onto a 3 year old post :icon_biggrin:

Try placing the following at the top of your php file(s) that process the uploads:

ini_set ('upload_max_filesize','10M');

That should allow the server to accept 10 Megabyte files and is the most common solution for this problem from previous posts of simular/same problems on these forums. Let me know if you need more info.

Glad to see you didn't back onto a 3 year old post :icon_biggrin:

Hi cwarn...
Ur code is working good for me also....
i have another doubt?
can we modify through php.ini.....?

that worked a treat thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.