1
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 types type JPEG 3 mega up 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: ./");
}
Add to the question the latest PHP error log messages pertaining to this script.
– Bacco
already took a look at the settings of php max_upload_site and max_post_size ?
– Otto
I have no error log, in the error message just say that it went wrong. Good idea, I’ll take a look at this max_upload.
– Pedro Henrique
Need to log error and use, is the minimum minimum if you want to use PHP for anything minimally serious.
– Bacco