1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Validate large file in server side

Discussion in 'PHP' started by piropeator, Aug 11, 2018.

  1. #1
    Hello! I have a simple code to upload a file to server.
    SEMrush
    <!DOCTYPE html>
    <html lang="es">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <form action="upload3.php" enctype="multipart/form-data" method="POST">
            <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
            Upload File: <input name="file_upload" type="file" />
            <input type="submit" value="Enviar fichero" />
        </form>
    </body>
    </html>
    HTML:
    In PHP:
    <?php
    define('APP_BASEDIR', dirname(__FILE__));
    $ruta = APP_BASEDIR . "/cargas/";
    
    $file_uploaded = $ruta. basename($_FILES['file_upload']['name']);
    
    if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $file_uploaded)) {
        echo "OK";
    } else {
        echo "ERROR!";
    }
    ?>
    PHP:
    If the file is small, there is no problem.
    But if the file is very large, it fails.
    Show this:
    And tell Notice: Undefined index... this because $_FILE are empty (see http://php.net/manual/en/ini.core.php#ini.post-max-size)
    I don't need to upload a large file. I just want to validate on the server side that a large file is not loaded (2Mb Max).
    Can someone help me?
     
    piropeator, Aug 11, 2018 IP
    SEMrush
  2. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #2
    RoseHosting, Aug 11, 2018 IP
  3. JEET

    JEET Well-Known Member

    Messages:
    2,275
    Likes Received:
    118
    Best Answers:
    2
    Trophy Points:
    185
    #3
    Its a variable in php.ini which is making the script fail. Increase its limit and script will continue as normal.

    ; Maximum size of POST data that PHP will accept.
    post_max_size = 8M


    Make this:
    post_max_size = 18M
    or
    post_max_size = 25M
    or so on... Whatever is needed...
     
    JEET, Sep 17, 2018 IP
  4. JEET

    JEET Well-Known Member

    Messages:
    2,275
    Likes Received:
    118
    Best Answers:
    2
    Trophy Points:
    185
    #4
    This one also needs to be increased.

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 2M
     
    JEET, Sep 17, 2018 IP