Jump to content

echo doesn't show


Go to solution Solved by dalecosp,

Recommended Posts

ok so i save the mime type in my database so when users download there file it will download the correct one but im having trouble displaying the echo any ideas?

<?php

    $get = $_GET['code'];

    if(!empty($get)){
    
    require "script/db.ini.php";
    
        $select = "SELECT * FROM files WHERE code='$get'";
        $return = mysqli_query($db,$select);
        
        $row = mysqli_fetch_assoc($return);

        $name = $row['name'];
        $code = $row['code'];
        $type = $row['type'];
        $size = $row['size'];
        $date = $row['date'];
        
        if($get !== $code){
        
        header("Location: http://website.me");
        
        }else{
        
            //
            // download the file
            //

        if($type == "application/x-zip-compressed"){

        	echo "<br></br><center>Your file is being downloaded <br><h2>$name</h2></center>";

        	header("Content-Type: application/x-zip-compressed");
            header('Content-Disposition: attachment; filename="'.$name.'"');
            header("Content-Transfer-Encoding: binary");
            header('Pragma: no-cache');
            header('Expires: 0');
            readfile("mypathfile/$name");
            
        }elseif($type == "application/octet-stream"){
        	echo "<br></br><center>Your file is being downloaded <br><h2>$name</h2></center>";

        	header("Content-Type: application/octet-stream");
            header('Content-Disposition: attachment; filename="'.$name.'"');
            header("Content-Transfer-Encoding: binary");
            header('Pragma: no-cache');
            header('Expires: 0');
            readfile("mypathfile/$name");

        }elseif($type == "image/jpeg"){
        	echo "<br></br><center>Your file is being downloaded <br><h2>$name</h2></center>";

        	header("Content-Type: image/jpeg");
            header('Content-Disposition: attachment; filename="'.$name.'"');
            header("Content-Transfer-Encoding: binary");
            header('Pragma: no-cache');
            header('Expires: 0');
            readfile("mypathfile/$name");
        }else{
        	echo "<center>Error</center>";
        }

        }

    }else{
        header("Location: http://website.me");
    }
?>

Link to comment
https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/
Share on other sites

  • Solution

Of course, that won't work, either, since the headers aren't text/html content-type.  An echo in a application/octet-stream would like not be a Good Thing.

Seems the best course of action would be "rethink the system".  If the user has clicked on a link to download something, he/she should already be aware that a download is going to occur ... seems like you don't really need to re-iterate the point to me...

Link to comment
https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460357
Share on other sites

echoing anything before the header will either prevent the header from being sent or if output buffering is on will become part of the downloaded data and corrupt the file and echoing anything after the header statements will also become part of the downloaded data and corrupt the file.

Link to comment
https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460361
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.