Rectangle 27 26

As noted in the edited question $_POST and $_FILES are empty when PHP silently discards data (happens when the actual data is bigger than post_max_size). Since HTTP header and $_GET remain intact those can be used to detect the discards.

if(intval($_SERVER['CONTENT_LENGTH'])>0 && count($_POST)===0){
    throw new Exception('PHP discarded POST data because of request exceeding post_max_size.');
}

Option b) Add a GET parameter that tells whether POST data is present.

Note: $_SERVER['CONTENT_LENGTH'] is not "always" set, the server host can disable this variable from being visible

Thanks, this is the answer!

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

html - PHP - empty $_POST and $_FILES - when uploading larger files - ...

php html
Rectangle 27 7

The problem is your post_max_size is the same size as upload_max_filesize which will cause the $_FILES array (and $_POST) to be empty. If you up the limit on the post_max_size, the $_FILES array will no longer be empty.

EDIT: Not sure why the negative vote. While it may not apply exactly in this case, it is worth mentioning. This is exactly what php.net says: http://www.php.net/manual/en/ini.core.php#ini.post-max-size.

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.

Negative vote was not mine. Sorry. I'll try what you said when I will have time. For the moment I gave up. Thank you.

@ChuckBurgess Its a true fact :)

arrays - PHP upload fail (empty $_FILES) - Stack Overflow

php arrays upload
Rectangle 27 2

if($_FILES['image']['error'] === UPLOAD_ERR_OK) {
    // Success code Goes here .. 
}

UPLOAD_ERR_OK returns value 0 if there is no error, the file was uploaded successfully.

php - $_FILES array is not empty upon uploading nothing - Stack Overfl...

php file upload
Rectangle 27 1

If no file is selected for upload in your form, PHP will return $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name'] as none.

You get an array entry per "file" upload field, even if the user didn't select a file to upload.

php - $_FILES array is not empty upon uploading nothing - Stack Overfl...

php file upload
Rectangle 27 1

I had recently encountered this same issue in php7.0. When I tried to upload 0.7G zip- $_POST,$_REQUEST and $_FILES were all empty but increasing upload_max_filesize and post_max_size values to correct limit in php.ini and restarting php7.0-fpm fixed it.

upload - $_FILES array empty in php when uploading .zip, while .jpg wo...

php upload zip
Rectangle 27 4

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$max_no_img=4; // Maximum number of images value to be set here

echo "<form method=post action='' enctype='multipart/form-data'>";
echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>";
for($i=1; $i<=$max_no_img; $i++){
echo "<tr><td>Images $i</td><td>
<input type=file name='images[]' class='bginput'></td></tr>";
}

echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>";
echo "</form> </table>";
while(list($key,$value) = each($_FILES['images']['name']))
{
    //echo $key;
    //echo "<br>";
    //echo $value;
    //echo "<br>";
if(!empty($value)){   // this will check if any blank field is entered
$filename =rand(1,100000).$value;    // filename stores the value

$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

$add = "upload/$filename";   // upload directory path is set
//echo $_FILES['images']['type'][$key];     // uncomment this line if you want to display the file type
//echo "<br>";                             // Display a line break
copy($_FILES['images']['tmp_name'][$key], $add); 
echo $add;
    //  upload the file to the server
chmod("$add",0777);                 // set permission to the file.
}
}
?>
</body>
</html>

Multiple file upload in php - Stack Overflow

php file-upload
Rectangle 27 1

<?php
IF (isset($_POST['submit'])) {

    $err = "";
    $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/x-png'); 
    $imgexts = array('gif', 'jpeg', 'jpg', 'png'); 

    IF (!empty($_FILES['file']['name'])) {

        $img = $_FILES['file']['name'];
        $temp = $_FILES['file']['tmp_name'];
        $ext = strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1));// file ext.
        $info = @getimagesize($_FILES['file']['tmp_name']); 
        $imgw = $info[0]; // width 
        $imgh = $info[1]; // height 
        $mime = image_type_to_mime_type($info[2]);

        IF (!in_array($ext, $imgexts)) { 
            $err .="<li>File type (".$ext.") is not supported. (Only ".implode(", ",$imgexts).")</li>"; // Non-supported file type 
        }ELSE{
            // 
            IF (!in_array($mime, $mimetypes)) { 
                $err .="<li>Mime type (".$mime.") is not supported. (Only ".implode(", ",$mimetypes).")</li>"; // Non-supported mime type 
            }

        }

    }ELSE{ 
        $err ="<li>Select a file to upload (".implode(", ",$imgexts).")</li>";
    }


    IF (!empty($err)) {

        echo '<p>Errors:</p><ul>'.$err.'</ul>';

    }ELSE{

        // good to go

    }

}ELSE{

    // form not sumbitted 


}
?>

html - PHP: File extension is empty when user uploads image with unall...

php html forms file-upload
Rectangle 27 2

<?php
if($_POST && isset($_FILES['file']))
{
    $recipient_email    = "recipient@yourmail.com"; //recepient
    $from_email         = "info@your_domain.com"; //from email using site domain.
    $subject            = "Attachment email from your website!"; //email subject line

    $sender_name = filter_var($_POST["s_name"], FILTER_SANITIZE_STRING); //capture sender name
    $sender_email = filter_var($_POST["s_email"], FILTER_SANITIZE_STRING); //capture sender email
    $sender_message = filter_var($_POST["s_message"], FILTER_SANITIZE_STRING); //capture message
    $attachments = $_FILES['file'];

    //php validation
    if(strlen($sender_name)<4){
        die('Name is too short or empty');
    }
    if (!filter_var($sender_email, FILTER_VALIDATE_EMAIL)) {
      die('Invalid email');
    }
    if(strlen($sender_message)<4){
        die('Too short message! Please enter something');
    }

    $file_count = count($attachments['name']); //count total files attached
    $boundary = md5("sanwebe.com"); 

    if($file_count > 0){ //if attachment exists
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from_email."\r\n"; 
        $headers .= "Reply-To: ".$sender_email."" . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

        //message text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($sender_message)); 

        //attachments
        for ($x = 0; $x < $file_count; $x++){       
            if(!empty($attachments['name'][$x])){

                if($attachments['error'][$x]>0) //exit script and output error if we encounter any
                {
                    $mymsg = array( 
                    1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 
                    2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 
                    3=>"The uploaded file was only partially uploaded", 
                    4=>"No file was uploaded", 
                    6=>"Missing a temporary folder" ); 
                    die($mymsg[$attachments['error'][$x]]); 
                }

                //get file info
                $file_name = $attachments['name'][$x];
                $file_size = $attachments['size'][$x];
                $file_type = $attachments['type'][$x];

                //read file 
                $handle = fopen($attachments['tmp_name'][$x], "r");
                $content = fread($handle, $file_size);
                fclose($handle);
                $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)

                $body .= "--$boundary\r\n";
                $body .="Content-Type: $file_type; name="$file_name"\r\n";
                $body .="Content-Disposition: attachment; filename="$file_name"\r\n";
                $body .="Content-Transfer-Encoding: base64\r\n";
                $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                $body .= $encoded_content; 
            }
        }

    }else{ //send plain email otherwise
       $headers = "From:".$from_email."\r\n".
        "Reply-To: ".$sender_email. "\n" .
        "X-Mailer: PHP/" . phpversion();
        $body = $sender_message;
    }

     $sentMail = @mail($recipient_email, $subject, $body, $headers);
    if($sentMail) //output success or failure messages
    {       
        die('Thank you for your email');
    }else{
        die('Could not send mail! Please check your PHP mail configuration.');  
    }
}
?>

Send attachments with PHP Mail()? - Stack Overflow

php
Rectangle 27 2

<?php
if($_POST && isset($_FILES['file']))
{
    $recipient_email    = "recipient@yourmail.com"; //recepient
    $from_email         = "info@your_domain.com"; //from email using site domain.
    $subject            = "Attachment email from your website!"; //email subject line

    $sender_name = filter_var($_POST["s_name"], FILTER_SANITIZE_STRING); //capture sender name
    $sender_email = filter_var($_POST["s_email"], FILTER_SANITIZE_STRING); //capture sender email
    $sender_message = filter_var($_POST["s_message"], FILTER_SANITIZE_STRING); //capture message
    $attachments = $_FILES['file'];

    //php validation
    if(strlen($sender_name)<4){
        die('Name is too short or empty');
    }
    if (!filter_var($sender_email, FILTER_VALIDATE_EMAIL)) {
      die('Invalid email');
    }
    if(strlen($sender_message)<4){
        die('Too short message! Please enter something');
    }

    $file_count = count($attachments['name']); //count total files attached
    $boundary = md5("sanwebe.com"); 

    if($file_count > 0){ //if attachment exists
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from_email."\r\n"; 
        $headers .= "Reply-To: ".$sender_email."" . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

        //message text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($sender_message)); 

        //attachments
        for ($x = 0; $x < $file_count; $x++){       
            if(!empty($attachments['name'][$x])){

                if($attachments['error'][$x]>0) //exit script and output error if we encounter any
                {
                    $mymsg = array( 
                    1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 
                    2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 
                    3=>"The uploaded file was only partially uploaded", 
                    4=>"No file was uploaded", 
                    6=>"Missing a temporary folder" ); 
                    die($mymsg[$attachments['error'][$x]]); 
                }

                //get file info
                $file_name = $attachments['name'][$x];
                $file_size = $attachments['size'][$x];
                $file_type = $attachments['type'][$x];

                //read file 
                $handle = fopen($attachments['tmp_name'][$x], "r");
                $content = fread($handle, $file_size);
                fclose($handle);
                $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)

                $body .= "--$boundary\r\n";
                $body .="Content-Type: $file_type; name="$file_name"\r\n";
                $body .="Content-Disposition: attachment; filename="$file_name"\r\n";
                $body .="Content-Transfer-Encoding: base64\r\n";
                $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                $body .= $encoded_content; 
            }
        }

    }else{ //send plain email otherwise
       $headers = "From:".$from_email."\r\n".
        "Reply-To: ".$sender_email. "\n" .
        "X-Mailer: PHP/" . phpversion();
        $body = $sender_message;
    }

     $sentMail = @mail($recipient_email, $subject, $body, $headers);
    if($sentMail) //output success or failure messages
    {       
        die('Thank you for your email');
    }else{
        die('Could not send mail! Please check your PHP mail configuration.');  
    }
}
?>

Send attachments with PHP Mail()? - Stack Overflow

php
Rectangle 27 2

<?php
if($_POST && isset($_FILES['file']))
{
    $recipient_email    = "recipient@yourmail.com"; //recepient
    $from_email         = "info@your_domain.com"; //from email using site domain.
    $subject            = "Attachment email from your website!"; //email subject line

    $sender_name = filter_var($_POST["s_name"], FILTER_SANITIZE_STRING); //capture sender name
    $sender_email = filter_var($_POST["s_email"], FILTER_SANITIZE_STRING); //capture sender email
    $sender_message = filter_var($_POST["s_message"], FILTER_SANITIZE_STRING); //capture message
    $attachments = $_FILES['file'];

    //php validation
    if(strlen($sender_name)<4){
        die('Name is too short or empty');
    }
    if (!filter_var($sender_email, FILTER_VALIDATE_EMAIL)) {
      die('Invalid email');
    }
    if(strlen($sender_message)<4){
        die('Too short message! Please enter something');
    }

    $file_count = count($attachments['name']); //count total files attached
    $boundary = md5("sanwebe.com"); 

    if($file_count > 0){ //if attachment exists
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from_email."\r\n"; 
        $headers .= "Reply-To: ".$sender_email."" . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

        //message text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($sender_message)); 

        //attachments
        for ($x = 0; $x < $file_count; $x++){       
            if(!empty($attachments['name'][$x])){

                if($attachments['error'][$x]>0) //exit script and output error if we encounter any
                {
                    $mymsg = array( 
                    1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 
                    2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 
                    3=>"The uploaded file was only partially uploaded", 
                    4=>"No file was uploaded", 
                    6=>"Missing a temporary folder" ); 
                    die($mymsg[$attachments['error'][$x]]); 
                }

                //get file info
                $file_name = $attachments['name'][$x];
                $file_size = $attachments['size'][$x];
                $file_type = $attachments['type'][$x];

                //read file 
                $handle = fopen($attachments['tmp_name'][$x], "r");
                $content = fread($handle, $file_size);
                fclose($handle);
                $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)

                $body .= "--$boundary\r\n";
                $body .="Content-Type: $file_type; name="$file_name"\r\n";
                $body .="Content-Disposition: attachment; filename="$file_name"\r\n";
                $body .="Content-Transfer-Encoding: base64\r\n";
                $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                $body .= $encoded_content; 
            }
        }

    }else{ //send plain email otherwise
       $headers = "From:".$from_email."\r\n".
        "Reply-To: ".$sender_email. "\n" .
        "X-Mailer: PHP/" . phpversion();
        $body = $sender_message;
    }

     $sentMail = @mail($recipient_email, $subject, $body, $headers);
    if($sentMail) //output success or failure messages
    {       
        die('Thank you for your email');
    }else{
        die('Could not send mail! Please check your PHP mail configuration.');  
    }
}
?>

Send attachments with PHP Mail()? - Stack Overflow

php
Rectangle 27 2

<?php
if($_POST && isset($_FILES['file']))
{
    $recipient_email    = "recipient@yourmail.com"; //recepient
    $from_email         = "info@your_domain.com"; //from email using site domain.
    $subject            = "Attachment email from your website!"; //email subject line

    $sender_name = filter_var($_POST["s_name"], FILTER_SANITIZE_STRING); //capture sender name
    $sender_email = filter_var($_POST["s_email"], FILTER_SANITIZE_STRING); //capture sender email
    $sender_message = filter_var($_POST["s_message"], FILTER_SANITIZE_STRING); //capture message
    $attachments = $_FILES['file'];

    //php validation
    if(strlen($sender_name)<4){
        die('Name is too short or empty');
    }
    if (!filter_var($sender_email, FILTER_VALIDATE_EMAIL)) {
      die('Invalid email');
    }
    if(strlen($sender_message)<4){
        die('Too short message! Please enter something');
    }

    $file_count = count($attachments['name']); //count total files attached
    $boundary = md5("sanwebe.com"); 

    if($file_count > 0){ //if attachment exists
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from_email."\r\n"; 
        $headers .= "Reply-To: ".$sender_email."" . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

        //message text
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($sender_message)); 

        //attachments
        for ($x = 0; $x < $file_count; $x++){       
            if(!empty($attachments['name'][$x])){

                if($attachments['error'][$x]>0) //exit script and output error if we encounter any
                {
                    $mymsg = array( 
                    1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 
                    2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 
                    3=>"The uploaded file was only partially uploaded", 
                    4=>"No file was uploaded", 
                    6=>"Missing a temporary folder" ); 
                    die($mymsg[$attachments['error'][$x]]); 
                }

                //get file info
                $file_name = $attachments['name'][$x];
                $file_size = $attachments['size'][$x];
                $file_type = $attachments['type'][$x];

                //read file 
                $handle = fopen($attachments['tmp_name'][$x], "r");
                $content = fread($handle, $file_size);
                fclose($handle);
                $encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)

                $body .= "--$boundary\r\n";
                $body .="Content-Type: $file_type; name="$file_name"\r\n";
                $body .="Content-Disposition: attachment; filename="$file_name"\r\n";
                $body .="Content-Transfer-Encoding: base64\r\n";
                $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
                $body .= $encoded_content; 
            }
        }

    }else{ //send plain email otherwise
       $headers = "From:".$from_email."\r\n".
        "Reply-To: ".$sender_email. "\n" .
        "X-Mailer: PHP/" . phpversion();
        $body = $sender_message;
    }

     $sentMail = @mail($recipient_email, $subject, $body, $headers);
    if($sentMail) //output success or failure messages
    {       
        die('Thank you for your email');
    }else{
        die('Could not send mail! Please check your PHP mail configuration.');  
    }
}
?>

Send attachments with PHP Mail()? - Stack Overflow

php
Rectangle 27 0

If no file is selected for upload in your form, PHP will return $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name'] as none.

You get an array entry per "file" upload field, even if the user didn't select a file to upload.

php - $_FILES array is not empty upon uploading nothing - Stack Overfl...

php file upload
Rectangle 27 0

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.

If you need the limit increased for a specific script, you can try ini_set('post-max-size', $size_needed);. I'm not sure if it can be overridden within a script, though; that limit is probably there to specifically keep you from doing what you're trying to do.

I am happy with my limits, but not the way php reacts when those limits are exceeded. Also the GET idea is a useful one, but I would like it to be transparent to the user, and it feels "hackish".

php - How to detect if a user uploaded a file larger than post_max_siz...

php file-upload php-5.3
Rectangle 27 0

Unless your upload form has fields other than the file input field, then $_POST should be empty - files are handled exclusively through the $_FILES. It's very odd that $_FILES would be empty if the post size is exceeded - the upload handlers have a specific error code (1/UPLOAD_ERR_INI_SIZE) to report such a condition. Also check that memory_limit is larger than the upload_max_filesize.

Your webserver may be blocking the upload as well, which would occur before PHP is invoked. On Apache, it's controlled by LimitRequestBody.

Yes a few other fields that under normal circumstances are there to identify what kind of upload it is. LimitRequestBody is set way above the php settings in this case and is not interfering.

Yes, I too am very surprised to find the _FILES empty just because of this.

Anything in the PHP and/or Apache error logs?

php - How to detect if a user uploaded a file larger than post_max_siz...

php file-upload php-5.3
Rectangle 27 0

The problem is your post_max_size is the same size as upload_max_filesize which will cause the $_FILES array (and $_POST) to be empty. If you up the limit on the post_max_size, the $_FILES array will no longer be empty.

EDIT: Not sure why the negative vote. While it may not apply exactly in this case, it is worth mentioning. This is exactly what php.net says: http://www.php.net/manual/en/ini.core.php#ini.post-max-size.

If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty.

Negative vote was not mine. Sorry. I'll try what you said when I will have time. For the moment I gave up. Thank you.

@ChuckBurgess Its a true fact :)

arrays - PHP upload fail (empty $_FILES) - Stack Overflow

php arrays upload
Rectangle 27 0

<?php
$uploadDir = '/uploads/';

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile   = $_FILES['Filedata']['tmp_name'];
    $uploadDir  = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
    $targetFile = $uploadDir . $_FILES['Filedata']['name'];

    // Save the file
    move_uploaded_file($tempFile, $targetFile);
    echo 1;

}

?>

How to allow all file types for upload in php? - Stack Overflow

php file-upload
Rectangle 27 0

<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
$targetFolder = '/uploads'; // Relative to the root

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
    move_uploaded_file($tempFile,$targetFile);
    echo '1';
} else {
    echo 'Invalid file type.';
}
}
?>
$fileParts = pathinfo($_FILES['Filedata']['name']);
$targetFile = rtrim($targetPath,'/') . '/' .rand_string(20).'.'.$fileParts['extension'];

Where rand_string() is a function that generates random stings.

php - Uploadify - Rename File - Stack Overflow

php javascript uploadify
Rectangle 27 0

Disabling this option causes $_POST and $_FILES not to be populated. The only way to read postdata will then be through the php://input stream wrapper. (... )

apache - Why would $_FILES be empty when uploading files to PHP? - Sta...

php apache file-upload
Rectangle 27 0

If $_POST and $_FILES are both empty then you've exceeded the maximum post size ini ('post_max_size')

There are several settings in php.ini, including the maximum for an individual file ('upload_max_filesize'), and the maximum for all uploads ('post_max_size'). Make sure those ini settings are set correctly

Be careful of syntax if you hve edited it, it's picky when handling M, K or G (not KB, MB or GB), and don't exceed the bit size of your server, i.e. don't go above 4billion bytes on a 32 bit server.

Other causes of $_FILES being empty, but not $_POST. You don't have enough free space to upload your files, or you don't have permissions ot write to the temp directory. Check /tmp has enough space, and that you can write to it as apache/php user.

$_POST is not empty... permission or lack of free space may not be the case here because when i'm uploading an image in a separate php file where i hav written the similar code for uploading but not of other updates as mention in the above code, my image is uploaded with that separate file. but not with the above code.

There appears nothing wrong with the code (that I can see) and you say other examples work - so server is fine. Is that all your code, then, and not edited? Most likely issue now is that you've edited from your real source to a working version above. Check the enctype exists in the original source, check that you only have one opening <form> element and one 'name="file"' input etc. That's all I can think of. If available publicly (the html part, not the php) can you post a link?

the above code is exactly what i'm running on my server... and the html part is in the above code i hav posted...

Absolutely stumped, then. My only 'last gasp" would be to suggest putting a URL in the "action", but can't see how that would help. So it's what I call "back to first principles" - take a bit of code that works elsewhere on the server, check it works here, then edit one line at a time until you get the code you need. Then compare the difference. Sorry - your code's fine (unless we're both missing it) so really no other suggestion.

It worked when I moved my code on an independent .php file. And when I needed to upload I gave the link to that page in which independent uploading code was written. I don't know the reason behind this but this is how I solved it.

php - How to upload an image and then store it in a database? - Stack ...

php file-upload
Rectangle 27 0

What's your php.ini's post_max_size? You have to adjust this value as well (8MB by default), that's why your $_POST array is empty.

EDIT: upload_max_filesize and post_max_size can't be changed using ini_set because their changeable state is set to PHP_INI_PERDIR (see http://be2.php.net/manual/en/ini.list.php) It should be PHP_INI_USER.

So, you obvisouly stick to the default values (probably 2M and 8M) hence the empty $_FILES.

You have to change these options using the server config (php.ini or apache conf) or a .htaccess file. See http://php.net/manual/en/configuration.changes.php

@phperroa: I think what paul.ago was trying to say is that you need to set it in the server configuration file, not in the script, because the script is run AFTER the upload exceeds the ini limit. Depsite Capsule claiming he stole his answer, paul might not have the comment ability.

If you don't have access to php.ini, you can try to add these options using php_value in a .htaccess file. See php.net/manual/en/configuration.changes.php

See my edit, your ini_set can't work by design. This limitation might be the result of what paul.ago was explaining.

PHP - Uploading one or two files (large photos) works fine - uploading...

php file-upload uploading