Sponsored Content
Top Forums Shell Programming and Scripting Downloading show garbage on the screen Post 302853505 by hadinetcat on Saturday 14th of September 2013 07:19:50 PM
Old 09-14-2013
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 09:03 PM.. Reason: Please use code tags, and indent code. Thanks.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing Garbage output

I am using following code to read myfile.ddl line by line. But the thing is it is printing lot of garbage which are the names of the files and directories in which myfile.ddl is present. Kindly refine the code so that only myfile.ddl contents are only read LOGFILE="logfile.txt"... (4 Replies)
Discussion started by: skyineyes
4 Replies

2. Shell Programming and Scripting

tail command not show on screen

Hi, I'm moniroting duplicate text with unix command (tail -f trace75747 | grep 'duplicate'), but it showed many lines then it stop show trace information although trace information in this file trace75747 always got. What should I do? I look forward to hearing from you. THANKS! (10 Replies)
Discussion started by: seyha_moth
10 Replies

3. OS X (Apple)

Virtual screen accessed by Screen Sharing

Hi, I'm trying to create a virtual screen, (maybe xvfb? or any other virtual screen buffer) and be able to use Screen Sharing to connect to it. The setup is that I have a Mac Mini connected to the TV. But when my girlfriend is using Front Row, I can't use Screen Sharing at the same time from... (0 Replies)
Discussion started by: linge
0 Replies

4. Shell Programming and Scripting

Logging ALL standard out of a bash script to a log file, but still show on screen

Is it possible to store all standard-out of a bash script and the binaries it calls in a log file AND still display the stdout on screen? I know this is possible to store ALL stdout/stderr of a script to a single log file like: exec 1>&${logFile} exec 2>&1 But running a script with the... (3 Replies)
Discussion started by: ckmehta
3 Replies

5. Programming

strcat outputs garbage

Anyone have any ideas why when using strcat function I would get some garbage at the beginning of the output string? what I'm doing is something like the following example. Code: char temp; char tempHolder; for(int i=0;i<something;i++){ sprintf(temp,"%u ", someVariable);... (2 Replies)
Discussion started by: airon23bball
2 Replies

6. Shell Programming and Scripting

Garbage value

I write a program to find a palindromic region in given sequences. but it dosen't seems to be run well. please give me your suggestions INPUT: AGCTAGCTCGAAGGTAG code is here #!/usr/bin/perl #Palindromic sequence print "enter the sequence:\n"; $rna = <STDIN>; chomp $rna; ... (3 Replies)
Discussion started by: sujit_singh
3 Replies

7. Red Hat

command line tool to disable screen lock and/or screen saver

Hi, I have a simple question : how to disable screen lock and/or sreen saver with command line with RHEL5.4 ? (1 Reply)
Discussion started by: albator1932
1 Replies

8. UNIX for Dummies Questions & Answers

Accidentally made a screen within a screen - how to move it up one level?

I made a screen within a screen. Is there a way to move the inner screen up one level so that it is at the same level as the first screen running from the shell? (2 Replies)
Discussion started by: phpchick
2 Replies

9. UNIX for Beginners Questions & Answers

Some % of Garbage Collection

I need to write a python script that will look at the local gc logs. 6 sys=0.00, real=0.06 secs] 2019-06-05T07:43:12.029-0500: 1072696.494: 2791209K->1995953K(2796544K)] 2803355K->1995953K(4164608K), , 3.0299555 secs] 2019-06-05T07:43:17.149-0500: 1072701.614: 3334321K->2008193K(4167680K),... (1 Reply)
Discussion started by: xgringo
1 Replies
HEADER(3)								 1								 HEADER(3)

header - Send a raw HTTP header

SYNOPSIS
void header (string $string, [bool $replace = true], [int $http_response_code]) DESCRIPTION
header(3) is used to send a raw HTTP header. See the HTTP/1.1 specification for more information on HTTP headers. Remember that header(3) must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(3), or require(3), functions, or another file access function, and have spaces or empty lines that are output before header(3) is called. The same problem exists when using a single PHP/HTML file. <html> <?php /* This will give an error. Note the output * above, which is before the header() call */ header('Location: http://www.example.com/'); exit; ?> PARAMETERS
o $string - The header string. There are two special-case header calls. The first is a header that starts with the string " HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code. <?php header("HTTP/1.0 404 Not Found"); ?> REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set. <?php header("Location: http://www.example.com/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> o $replace - The optional $replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in FALSE as the second argument you can force multiple headers of the same type. For example: <?php header('WWW-Authenticate: Negotiate'); header('WWW-Authenticate: NTLM', false); ?> o $http_response_code - Forces the HTTP response code to the specified value. Note that this parameter only has an effect if the $string is not empty. RETURN VALUES
No value is returned. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.2 | | | | | | | This function now prevents more than one header | | | to be sent at once as a protection against header | | | injection attacks. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 Download dialog If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Dispo- sition header to supply a recommended filename and force the browser to display the save dialog. <?php // We'll be outputting a PDF header('Content-Type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"'); // The PDF source is in original.pdf readfile('original.pdf'); ?> Example #2 Caching directives PHP scripts often generate dynamic content that must not be cached by the client browser or any proxy caches between the server and the client browser. Many proxies and clients can be forced to disable caching with: <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> Note You may find that your pages aren't cached even if you don't output all of the headers above. There are a number of options that users may be able to set for their browser that change its default caching behavior. By sending the headers above, you should override any settings that may otherwise cause the output of your script to be cached. Additionally, session_cache_limiter(3) and the session.cache_limiter configuration setting can be used to automatically gen- erate the correct caching-related headers when sessions are being used. NOTES
Note Headers will only be accessible and output when a SAPI that supports them is in use. Note You can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling ob_start(3) and ob_end_flush(3) in your script, or setting the out- put_buffering configuration directive on in your php.ini or server configuration files. Note The HTTP status header line will always be the first sent to the client, regardless of the actual header(3) call being the first or not. The status may be overridden by calling header(3) with a new status line at any time unless the HTTP headers have already been sent. Note There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround. There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading to Service Pack 2 or later. Note If safe mode is enabled the uid of the script is added to the realm part of the WWW-Authenticate header if you set this header (used for HTTP Authentication). Note HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname(3) to make an absolute URI from a relative one yourself: <?php /* Redirect to a different page in the current directory that was requested */ $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\'); $extra = 'mypage.php'; header("Location: http://$host$uri/$extra"); exit; ?> Note Session ID is not passed with Location header even if session.use_trans_sid is enabled. It must by passed manually using SID con- stant. SEE ALSO
headers_sent(3), setcookie(3), http_response_code(3), The section on HTTP authentication. PHP Documentation Group HEADER(3)
All times are GMT -4. The time now is 12:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy