Error while uploading some photos

Asked

Viewed 51 times

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: ./");
}
  • 1

    Add to the question the latest PHP error log messages pertaining to this script.

  • 2

    already took a look at the settings of php max_upload_site and max_post_size ?

  • 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.

  • 1

    Need to log error and use, is the minimum minimum if you want to use PHP for anything minimally serious.

2 answers

2

It can be something of configuration, when going to check which type of image can go up must tbm put the maximum size allowed,have a chunk in codeigniter that would be:

$config['upload_path'] = './public/images/noiva';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2000;
$config['max_width'] = 1024;
$config['max_heigth'] = 768;

You would have to see how it would look in PHP root.

  • Valeus, I didn’t even realize!

  • I’m gonna run some tests

2

Well it’s probably a setup on your php.ini

Search your php.ini for these settings:

post_max_size
upload_max_filesize

And change them to a higher number, after changing, try again to insert an image.

  • has a way to use htaccess for this?

  • To use PHP configuration in . htaccess, you will need mod_php installed on the server, otherwise it will give you an "Internal Server Error". Having that installed, then you put in . htaccess: php_value upload_max_filesize 10M. Reference: Here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.