How do I resolve a file upload error code 2?

0

<form enctype="multipart/form-data" action="eje02.php" method="post">

 <input type="hidden" name="MAX_FILE_SIZE" value="2000000"/> 


Send this file: <input name="userfile" type="file"  value="" />
<input type="submit" value="Send File">
</form>

The PHP file:

if(  is_uploaded_file(  $_FILES['userfile']['tmp_name'])   ){
    print "<h1> Archivo subido!</h1>"; 

}else{
    /** Hubo un error */
    $codigo_de_error= $_FILES['userfile']['error'];
    $mensaje="";

    switch(  $codigo_de_error){
    case UPLOAD_ERR_OK: //valor 0
        $mensaje="Archivo subido correctamente";
        break;
    case UPLOAD_ERR_INI_SIZE:
        $mensaje="El fichero subido excede la directiva upload_max_size de php.ini";
        break;
    case UPLOAD_ERR_FORM_SIZE:
        $tama= ( (int)$_FILES['userfile']['size']  )/1024;

        $mensaje="El fichero subido excede la directiva MAX_FILE_SIZE especificada 
        en el formulario,  Size del archivo es $tama";
        break;
    case UPLOAD_ERR_PARTIAL:
        $mensaje="Archivo parcialmente subido";
        break;
    case UPLOAD_ERR_NO_FILE:
        $mensaje="No se subio ningun fichero";
        break;
    case UPLOAD_ERR_NO_TMP_DIR:
        $mensaje="Falta la carpeta temporal. ( desde php 5.0.3)";
        break;
    case UPLOAD_ERR_CANT_WRITE:
        $mensaje="No se pudo escribir el fichero en el disco (desde php 5.1.0)";
        break;
        case UPLOAD_ERR_EXTENSION:
        $mensaje="Una extension de PHP detuvo la subida del fichero (desde php 5.2.0)";
        break;
    }
    print "Codigo {$_FILES['userfile']['error']}  ,  $mensaje";
}

I just want to upload the file and no more, but I have seen in the php.ini that the maximum upload size is 2M, so I have put 2000000 for the MAX_FILE_SIZE, and still generates the error 2. Any suggestions?

A close to the server, I'm using xamp

allow_url_fopen On  On
allow_url_include   Off Off
arg_separator.input &   &
arg_separator.output    &   &
auto_append_file    no value    no value
auto_globals_jit    On  On
auto_prepend_file   no value    no value
browscap    C:\xampp\php\extras\browscap.ini    C:\xampp\php\extras\browscap.ini
default_charset UTF-8   UTF-8
default_mimetype    text/html   text/html
disable_classes no value    no value
disable_functions   no value    no value
display_errors  Off On
display_startup_errors  On  On
doc_root    no value    no value
docref_ext  no value    no value
docref_root no value    no value
enable_dl   Off Off
enable_post_data_reading    On  On
error_append_string no value    no value
error_log   C:\xampp\php\logs\php_error_log C:\xampp\php\logs\php_error_log
error_prepend_string    no value    no value
error_reporting 22527   22527
expose_php  On  On
extension_dir   C:\xampp\php\ext    C:\xampp\php\ext
file_uploads    On  On
hard_timeout    2   2
highlight.comment   #FF8000 #FF8000
highlight.default   #0000BB #0000BB
highlight.html  #000000 #000000
highlight.keyword   #007700 #007700
highlight.string    #DD0000 #DD0000
html_errors On  On
ignore_repeated_errors  Off Off
ignore_repeated_source  Off Off
ignore_user_abort   Off Off
implicit_flush  Off Off
include_path    C:\xampp\php\PEAR   C:\xampp\php\PEAR
input_encoding  no value    no value
internal_encoding   no value    no value
log_errors  On  On
log_errors_max_len  1024    1024
mail.add_x_header   On  On
mail.force_extra_parameters no value    no value
mail.log    no value    no value
max_execution_time  30  30
max_file_uploads    20  20
max_input_nesting_level 64  64
max_input_time  60  60
max_input_vars  1000    1000
memory_limit    128M    128M
open_basedir    no value    no value
output_buffering    4096    4096
output_encoding no value    no value
output_handler  no value    no value
post_max_size   8M  8M
precision   14  14
realpath_cache_size 4096K   4096K
realpath_cache_ttl  120 120
register_argc_argv  Off Off
report_memleaks On  On
report_zend_debug   On  On
request_order   GP  GP
sendmail_from   no value    no value
sendmail_path   no value    no value
serialize_precision -1  -1
short_open_tag  Off Off
SMTP    127.0.0.1   127.0.0.1
smtp_port   25  25
sys_temp_dir    no value    no value
track_errors    Off Off
unserialize_callback_func   no value    no value
upload_max_filesize 40M 40M
upload_tmp_dir  C:\xampp\tmp    C:\xampp\tmp
user_dir    no value    no value
user_ini.cache_ttl  300 300
user_ini.filename   .user.ini   .user.ini
variables_order GPCS    GPCS
windows.show_crt_warning    Off Off
xmlrpc_error_number 0   0
xmlrpc_errors   Off Off
zend.assertions 1   1
zend.detect_unicode On  On
zend.enable_gc  On  On
zend.multibyte  Off Off
zend.script_encoding    no value    no value
    
asked by Sonia Toledo 03.02.2018 в 21:08
source

1 answer

2

With putting that value is not enough. That is to control it in the client, but in the server you must also increase the maximum size of the file.

In the php.ini look at the following variable ; Maximum allowed size for uploaded files. upload_max_filesize = 40M

    
answered by 03.02.2018 / 23:28
source