I made a script that uploads a photo to the server and saves the name in MySQL, but some photos it does not send, some 3 mega pixels type JPEG is not sent and gives error.
index.php:
<form action="upload.php" method="POST" enctype="multipart/form-data">
<div>
<label for="foto">Foto do Perfil</label>
<input type="file" id="foto" name="foto">
<button type="submit" >enviar</button>
</div>
</form>
upload.php:
<php
session_start();
$email = $_SESSION['email'];
include_once("../../assets/tools/config.php");
$nome_temporario = $_FILES["foto"]["tmp_name"];
$nome_real = $_FILES["foto"]["name"];
copy($nome_temporario,"../../assets/userPic/$nome_real");
$foto = $_FILES['foto']["name"];
$url = $base_url."assets/userPic/".$foto;
//atualizar no BD
$sql = "UPDATE users SET foto='$url' WHERE email='$email'";
$salvar = mysqli_query($conn, $sql);
//Verificar se salvou no banco de dados
if(mysqli_affected_rows($conn)){
$_SESSION['msg'] = "<div class='alert alert-success'>Perfil atualizado com sucesso!
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>";
header("Location: ./");
} else {
$_SESSION['msg'] = "<div class='alert alert-danger'> Erro ao atualizar seu perfil! :(
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>";
header("Location: ./");
}