SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error while downloading file getting binary data instead of the actually file

    getting error while downloading file, getting binary data to the browser instead of the actually file, specially pdf files. im using BLOB data type in mysql filed.
    also tried ob_end_clean but not helping.

    v?xb(‏ه ‏zٍڈzTَکQىxSَ‏jآYoف5KKoصتمح+:وloوnأ"گ Oّزـw8^uLٹ-ئpfچ+أجشر د؛-ںeؤRH hْDyے#=@'X'ذXtzرص0Lوٍء{ڈے }f؛ِBک*ژكگyeطPepy,تًِMRwگCيٹ}Fzى3eNAو^4{j=رجسل<5Mz&@+*MYN1ُCںq)زذشM nj*]T*h03D*6غإQ.gءwي|م+sكmٍاeغوؤ~لں$/ھ(!@]ظtحز4CQeں[ظ5گ+ہ4MQd@ں|فژd؟F*xز پi?ـسخMأ}قَOe$ِ 'ظgءl=fRن(rإهـPy2ش2ج:طQ49t رA3kfفذ){'7ذE=نxةLb|شاـs لةأجثSyyuھc>*ا/Z9Vٍبش&ةqs؟Yعlzگگ_vئ؟!؟د h=لّےJ‏تْںبbU;Lآڑeڑ}كFپ ںUنvi>]vWBڑ!ج=41حز ہحٹ?لqع ض4فلtڑgؤbوTةEچ8س#ںآEW9ھr 8ژz$SW xضث؛iسؤ:pاYهسaکؤvCصژkچ ژr\W"Tؤ'<غ<،ئ ًيFلرکًظ(WVتG{i> stream xه]ڈeإqXXVثs1ث ;ADٹEت7[Hd'N"ضرے_JUWَُsgw#ygخمVWuWWW?~O(صA‏ةفكدےxW‏4ٌ;Hkز؟ے_ؤSر~ےQ*pئC0؛{,==َgqً?H،l{[:گJ‏Uي؛ٍص,أوm)>ٌ6ف*ےR:^[ثٹ3mض إVeززF{{0BM*ڑںخVيئ[ّ هYPG6Eغn{[Rآددءىفس*~=ِ/

    here is my php code for downloading

    Code PHP:
    <?php
     
     
    $company =$_GET['company'];
     
    // Make sure an ID was passed
    if(isset($_GET['id'])) {
    // Get the ID
    $id = intval($_GET['id']);
    // Make sure the ID is in fact a valid ID
    if($id <= 0) {
    die('The ID is invalid!');
    }
    else {
    // Connect to the database
    $dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
    if(mysqli_connect_errno()) {
        die("MySQL connection failed: ". mysqli_connect_error());
    }
     
    // Fetch the file information
    $query = "
        SELECT mime, name, size, data
        FROM $company
        WHERE id = $id";
    $result = $dbLink->query($query);
     
    if($result) {
        // Make sure the result is valid
        if($result->num_rows == 1) {
        // Get the row
            $row = mysqli_fetch_assoc($result);
     
            // Print headers
            header("Content-Type: ". $row['mime']);
            header("Content-Length: ". $row['size']);
            header("Content-Disposition: attachment; filename=". $row['name']);
     
            // Print data
            echo $row['data'];
        }
        else {
            echo 'Error! No image exists with that ID.';
        }
     
        // Free the mysqli resources
        @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 Mittineague; Aug 30, 2013 at 20:19. Reason: reformatting bbcode tags

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try using the following as your content type which should trigger the download correctly.

    Code:
    Content-Type: application/octet-stream
    Also I would highly recommend you steer clear of BLOB's for storing data in especially for files as they are slow, consume a lot of memory and make debugging very hard compared to using real files stored on the disk which only consume I/O and CPU resources.

  3. #3
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    chris.upjohn, i tried using it, but doesn't work.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •