Invalid argument for chmod ()?

0

I'm trying to get the dimensions of each photo sent, but when I run the file it happens:

Error:

  Warning: chmod(): Invalid argument in C:\Program Files (x86)\EasyPHP-
  Devserver-17\eds-www\PPI\adm\cadastrar_jogo.php on line 15

  Warning: getimagesize(): Filename cannot be empty in C:\Program Files   
  (x86)\EasyPHP-Devserver-17\eds-www\PPI\adm\cadastrar_jogo.php on line 16

Here's the part of the code that's giving the error:

    for ($i = 0; $i < count($_FILES['img']); $i++){
    if (isset($_FILES['img']['name'][$i])){
    if (!empty($_FILES['img']['name'][$i])){
     chmod($_FILES['img']['tmp_name'][$i], 0777);
      list ($larg, $alt) = getimagesize($_FILES['img']['tmp_name'][$i]);
          $verifica_quant_img++;

How can I solve the problem, and what exactly is the problem?

    
asked by anonymous 06.12.2017 / 02:10

1 answer

0

But it does not make much sense to use chmod in a file that is in the ./tmp folder of the operating system, you should first use move_upload and then apply chmod to the new destination.

It would also be interesting to check if there was an error with $_FILES['img']['error'] , see an example usage:

if (empty($_FILES['imagem']['name'])) {
    echo 'Você não selecionou nenhum arquivo';//Aqui você pode trocar por um alert ou customizar como desejar, é um aviso que o usuário provavelmente não selecionou nada
} else {
    $arquivos = $_FILES['img'];
    $total = count($arquivos['name']);

    for ($i = 0; $i < $total; $i++) {
        $nome = $arquivos['name'][$i];

        if ($arquivos['error'][$i] !== UPLOAD_ERR_OK) {
            echo 'Erro ao fazer upload de ', htmlspecialchars($nome), '<br>';
            continue;
        }

        $destino = 'pasta/foo/bar/' . $nome;

        if (move_uploaded_file($arquivos['tmp_name'][$i], $destino)) {
            echo 'O arquivo ', htmlspecialchars($nome),' foi carregado<br>';
            chmod($destino, 0777);
        } else {
            echo 'O arquivo ', htmlspecialchars($nome),' não foi carregado<br>';
        }
    }
}

However, I think using 0777 is overkill for images, maybe 644 is more than enough.

    
06.12.2017 / 02:18