Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 700

php readfile() problem on download content (i read all related posts before send it)

$
0
0

I'm having trouble creating a secure download on my site, it's not uploaded yet and it's currently being tested on the xampp server on my PC. It should be noted that my operating system is Windows 11this is my code:user click on a download link (jquery):

$(document).on('click','.downfile',function(e){  e.preventDefault();  var reqfile=$(this).next().val();  $.post('php/downloadfile.php',{    reqfile:reqfile    },function(data){});});

I divided the download file into two parts because someone on this site said that this might be the problem.so first part is:

<?php$file_path = "../uploads/".$_POST['reqfile'];if (file_exists($file_path)){  $_SESSION['download']=$file_path;  header('location: startdownload.php');}?>
<?phpsession_start();header('Content-Description: File Transfer');header('Content-Type: '. mime_content_type($_SESSION['download']));header('Content-Disposition: attachment; filename="'.basename($_SESSION['download']).'"');header('Content-Transfer-Encoding: binary');header('Expires: 0');header('Cache-Control: must-revalidate, post-check=0, pre-check=0');header('Pragma: public');header('Content-Length: ' . filesize($_SESSION['download']));ob_clean();flush();ob_end_flush();readfile($_SESSION['download']);exit;?>

and result is:firefox developer modeAs you can see, the file is loaded correctly but not downloaded.And the interesting thing is that the same code was working last week and the file was being downloaded. I have only made a small change in the code that has nothing to do with this section and moved the files folder one level further, for example:It was uploads/1/test.jpg and now it is uploads/1/1/test.jpg

please help me to solve this problem.


Viewing all articles
Browse latest Browse all 700

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>