Syed Nizamudeen
Syed Nizamudeen

Reputation: 440

Unable to POST form with max_filesize

Upload file is working fine with file size less than 2.9 MB but my phpinfo (localhost) showing upload_max_filesize 64M.

When trying to upload larger files, after form submit $_POST is empty and no file where uploaded.

here is my code:

        <?php
            function fileUpload($attachment){
                $target_file = UPLOADDIR.basename($attachment["name"]);
                if (file_exists($target_file)) {
                    return "Sorry, file already exists.";
                }
                if (move_uploaded_file($attachment["tmp_name"], $target_file)) {
                    return "The file ". basename( $attachment["name"]). " has been uploaded.";
                } else {
                    return $attachment;
                    return "Sorry, there was an error uploading your file.";
                }
            }
            if(isset($_POST["submit"])) {
                fileUpload($_FILES['fileToUpload'])
            }
        ?>

        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
            Select image to upload:
            <input type="file" name="fileToUpload" id="fileToUpload">
            <input type="submit" value="Upload Image" name="submit">
        </form>

Upvotes: 2

Views: 149

Answers (1)

Ajeet Kumar
Ajeet Kumar

Reputation: 815

Before uploading script you can set maximum upload size in your php code

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

or You need to set the value of upload_max_filesize and post_max_size in your php.ini :

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

After that run your code

and

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

Place this at the top of your PHP script and let your script loose!

if you made any change or modifying php.ini file(s), you need to restart your HTTP server(or localhost) to use new configuration.

Upvotes: 3

Related Questions