-1
<?php
require_once __DIR__ . '/db.php';
if (isset($_GET['image_id'])) {
    $sql = "SELECT imageType,imageData FROM tbl_image WHERE imageId=?";
    $statement = $conn->prepare($sql);
    $statement->bind_param("i", $_GET['image_id']);
    $statement->execute() or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysqli_connect_error());
    $result = $statement->get_result();

    $row = $result->fetch_assoc();
    header("Content-type: " . $row["imageType"]);
    echo $row["imageData"];
}
?>

as such there is no error in code just when i tried to download file there is empty image is coming as output. no data is present in image i want img should get data and give the proper output

also this same code is running in local xampp database. with same database export and import in my local pc

  • 3
    Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. Instead of building queries with string concatenation, always use [**prepared statements**](https://secure.php.net/manual/en/pdo.prepare.php) with [**bound parameters**](https://secure.php.net/manual/en/pdostatement.bindparam.php). See [**this page**](https://phptherightway.com/#databases) and [**this post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) for some good examples. – Alex Howansky Aug 28 '23 at 15:05
  • 1
    _"not working"_ is not helpful. What is not working? What error are you getting? What's in the server logs? What are you expecting to happen? What is actually happening? Please see [**How do I ask a good question?**](https://stackoverflow.com/help/how-to-ask) – Alex Howansky Aug 28 '23 at 15:08
  • Please check the PHP version of the hosting service you use in hostinger (if the PHP version is too old, `[ ]` syntax will not work) – Ken Lee Aug 28 '23 at 15:45
  • php version is latest 8.2.5 – Rajesh Pawar Aug 29 '23 at 13:45

0 Answers0