0
I have in a certain area of the system a form to uplevel images movies and music, this part usually only appears to administrator, but now it will be released to some types of users, I wanted to know how I do to determine the maximum size of the files, and how long it is safe not to flood the server, audio I wanted at most 4 minutes, videos at most 2 minutes for images I have no idea, the code I made
- I want to set the maximum upload size
- I need to add some more detail for security?
- I looked it up and found $_FILES['arquivo']['size']but I didn’t understand how to use, how I define the sizes, whether it is in 2M equal in php.ini or if I have to put the exact number type 2048
- The code is good like this?
IF(isset($_POST['btnenviar'])){
    if(isset($_FILES['arquivo'])){
        date_default_timezone_set("Brazil/East"); //Definindo timezone padrão
        $ext = strtolower(substr($_FILES['arquivo']['name'],-4)); //Pegando extensão do arquivo
        $novo_nome = "picture". rand(0,9999) . $ext; //Definindo um novo nome para o arquivo
        if(substr($novo_nome, -4) == '.jpeg' || substr($novo_nome, -3) == 'jpg' || substr($novo_nome, -3) == 'png' || substr($novo_nome, -3) == 'gif'){
            $resultado = TRUE;
        if($resultado == TRUE){
            $dir = 'arquivos/picture/'; //Diretório para uploads
            move_uploaded_file($_FILES['arquivo']['tmp_name'], $dir.$novo_nome); //Fazer upload do arquivo
            echo "✔Imagem Inserida!";
        }else{
            echo "erro critico entre em contato com administrador do sistema";
        }
        }else{
            echo "✖ Impossivel, extensão invalida!";
        }
    }
} else {
    echo 'teste';
}
About the central question I will not know how to help, but about how to improve: 1 - Not always the extension will be the last 4 characters, I advise to use
$path_info = pathinfo($_FILES['arquivo']['tmp_name']); $ext = $path_info['extension'];to catch. 2 - The name with a Random has many chances to repeat itself and end up overwriting the file. Usetime()it returns a UNIXTIMESTAMP that will be unique.– edson alves
about Rand I don’t use it in the system, I just put it in the code so you can test, actually at the time of uploading the image I register it in the database, and her new id is always the database id, so never repeat, I’ll take a look at the thankssss path_info
– Martins Luan