Problem uploading files [closed]

1

I have a code block to do upload files, however whenever I try to upload a message appears saying "Please send files with the following extensions: jpg, png or gif ". I'm trying to upload a docx file and I've already specified this:

$_UP['extensoes'] = array('docx', 'xlsx', 'pdf', 'jpg', 'png', 'gif', 'jpeg' );

Why does the message appear even though I have "freed" other extensions?

$extensao = @strtolower(end(explode('.', $_FILES['arquivoJuridico']['name'])));
if (array_search($extensao, $_UP['extensoes']) === false) {
   echo "Por favor, envie arquivos com as seguintes extensões: jpg, png ou gif";
}
    
asked by anonymous 19.01.2015 / 13:18

1 answer

1

I ran a test and it worked:

$_UP['extensoes'] = array('docx', 'xlsx', 'pdf', 'jpg', 'png', 'gif', 'jpeg' );
$extensao = @strtolower(end(explode('.', "nome.doc")));
if (array_search($extensao, $_UP['extensoes']) === false) {
   echo "Por favor, envie arquivos com as seguintes extensões: jpg, png ou gif";
}
$extensao = @strtolower(end(explode('.', "nome.docx")));
if (array_search($extensao, $_UP['extensoes']) === false) {
   echo "Por favor, envie arquivos com as seguintes extensões: jpg, png ou gif";
}

See running on ideone .

Otherwise you have some problem that you can not identify by what you posted in the question. One possibility is the filename is not coming correctly in $_FILES['arquivoJuridico']['name'] .

Do not compare directly with true or false to a location that expects a Boolean expression.

Another thing, when you put @ to execute something, you probably know that it gives an error. The @ only hides the error, does not make the execution correct.

    
19.01.2015 / 13:48