Downloading show garbage on the screen | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Downloading show garbage on the screen

Shell Programming and Scripting


Tags
php, php apache download

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-14-2013
hadinetcat hadinetcat is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 1 January 2014, 2:10 PM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Downloading show garbage on the screen

I have PHP code for downloading pdf files from mysql database. The code is working fine in firefox mozilla and google chrome but not in IE 10, it show garbage in the screen. I have debugged the code with some headers utilities to examine the headers request, it appear the headers is not sending back to the user agent (IE browser) it just blank.

my php code

Code:
<?php
ob_start();
$company =$_GET['company'];
if(isset($_GET['id']))
{
  $id = intval($_GET['id']);
  if($id <= 0)
  {
    die('The ID is invalid!');
  }
  else
  {
    $dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
    if(mysqli_connect_errno())
    {
      die("MySQL connection failed: ". mysqli_connect_error());
    }
    $query = "SELECT mime, name, size, data FROM $company WHERE id = $id";
    $result = $dbLink->query($query);
    if($result)
    {
      if($result->num_rows == 1) {
        $row = mysqli_fetch_assoc($result);
        $size = $row['size'];
        $filename = $row['name'];
        $data = $row['data'];
        $mime = $row['mime'];
        ini_get('zlib.output_compression');
        ini_set('zlib.output_compression', 'Off');
        header('Content-Type: application/pdf');
        while (@ob_end_clean());
        header('Content-Disposition: attachment; filename='.($filename));
        header('Content-Length:'.($size));
        echo $data;
        exit();
      }
      else
      {
        echo 'Error! No image exists with that ID.';
      }
      mysqli_free_result($result);
    }
    else
    {
      echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
    }
    mysqli_close($dbLink);
  }
}
else
{
  echo 'Error! No ID was passed.';
}
?>


Last edited by Scott; 09-14-2013 at 08:03 PM.. Reason: Please use code tags, and indent code. Thanks.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
command line tool to disable screen lock and/or screen saver albator1932 Red Hat 1 10-20-2011 04:43 PM
Logging ALL standard out of a bash script to a log file, but still show on screen ckmehta Shell Programming and Scripting 3 09-29-2009 04:19 PM
tail command not show on screen seyha_moth Shell Programming and Scripting 10 12-27-2008 09:26 AM
new NIC card doesn't show in show-nets iperez Solaris 13 09-26-2008 04:52 AM



All times are GMT -4. The time now is 12:27 AM.