Skip to content
Advertisement

Upload longblob works in local but not in web server

I have a php file that loads an image and receives a text, then sends them to another .php that runs a query to save the data in the database … everything works fine in my local version, but in the version Web only the text is saved, the longblob does not.

I tried to debug using $_FILES[‘error’], mysqli_sql_exception, error_reporting, etc… but no warning or error appears.

I know there are similar posts and I checked them but none of them helped me

The version of php in local and server is 7.3 and the mysql property max_allowed_packet is 20M in both.

This send the data:

<form enctype="multipart/form-data" method="post" action="php/saveImage.php" enctype="multipart/form-data">
<div class="form-group">
    <label for="classification" class="control-label">classification</label>
    <input type="text" class="form-control" id="classification" placeholder="..."  maxlength="50" name="classification" required>
</div>
<div class="form-group">
    <label for="image" class="control-label">Image</label>
    <input type="file" id="imagen" name="imagen" accept=image/*>
</div>
<input type="submit" class="btn btn-primary" value="Save">
</form>

and this get and save the data:

<?php
session_start();
include 'Connection.php';
$connection = new Connection();
$conn = $connection-> getConnection();

$classification = $_POST['classification'];
$blob = addslashes(file_get_contents($_FILES['image']['tmp_name']));

$sql = "INSERT INTO gallery (image, title) VALUES ('$blob', '$classification')";
$result = mysqli_query($conn, $sql);

if ($result) {
    echo "Success";
} else {
    echo "Error";
}
?>

Update: I know the code has security vulnerabilities and bad practices, but is not the point now, is for a personal use only.

Advertisement

Answer

The problem was the type of data in the database was blob and not longblob.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement