ecabrera Posted November 27, 2013 Share Posted November 27, 2013 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/ Share on other sites More sharing options...
dalecosp Posted November 27, 2013 Share Posted November 27, 2013 You can't send output to the browser before a header() call. Quote Link to comment https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460350 Share on other sites More sharing options...
ecabrera Posted November 27, 2013 Author Share Posted November 27, 2013 so would i have to put OB_START on top? Quote Link to comment https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460351 Share on other sites More sharing options...
Ch0cu3r Posted November 27, 2013 Share Posted November 27, 2013 No move the echo's so they after are setting the headers Quote Link to comment https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460355 Share on other sites More sharing options...
Solution dalecosp Posted November 27, 2013 Solution Share Posted November 27, 2013 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... Quote Link to comment https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460357 Share on other sites More sharing options...
mac_gyver Posted November 27, 2013 Share Posted November 27, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284329-echo-doesnt-show/#findComment-1460361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.