php - SQL Image doesn't display with header-content -


i have images stored on mysql database, longblob type column, when try display them on browser on chorme see little white box, , on firefox see , error message saying image file has problem.

this use display image.

$query = "select file, type uploads ref = '$ref'"; $statement = $pdo->prepare($query); $statement->execute(); $row = $statement->fetch(pdo::fetch_assoc);  header("content-type: " . $row["type"]); echo $row["file"]; 

note: $row["type"] mime type of file. think image isn't corrupted because can display this.

echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['file'] ).'"/>'; 

but need other way, curious thing few days ago worked fine same code. perhaps mysql fault?

edit code of upload.

function uploader_upload($file, $ref) {      $uploader = $_login["userid"];           $name = $file["name"];     $type = $file["type"];     $tmp_name = $file["tmp_name"];     $note = $file["note"];     $insert_file = mysql_escape_string(file_get_contents($tmp_name));                  $query = "insert uploads (file, name, type, uploader, ref, note) values ('$insert_file', '$name', '$type', '$uploader', '$ref', '$note')";     $statement = $pdo->prepare($query);     $statement->execute();     $refs[] = $ref;      return $refs; } 

ok, find problem, seems echo slipped includes of php , corrupting image.

if have same problem, make sure no echo or print or error shows.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -