Jump to content

echo doesn't show


ecabrera

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.