How to give a file to the browser through PHP, without downloading? I used this

header("Content-Disposition: attachment; filename='" . basename($filename) . "'"); header("Content-Length: " . filesize($local_filename)); header('Content-type: '.$mimeType.';'); readfile($local_filename); 

But the file is immediately downloaded ... I need it to be issued by the link, so that I can use this link in the player

  • try to remove the line from Content-Disposition: attachment... - this forces the browser to save the file. - Sergiks

1 answer 1

You have already practically brought your answer: the file is issued using PHP.

What the browser will do with this depends on the mime type. For example, if Content-type: text / plain, then the browser will try to simply display the content. If Content-type: application / octet-stream is set (these are all binary files and files that the web server doesn’t know mime), the browser may offer to download the file (especially if Content-Disposition is set: attachment)

Therefore, the formal answer is to force text / plain and remove Content-Disposition: attachment if there is. At the same time in the browser window you will see a jumble of characters - but you can copy the url from the address bar to paste it into the browser.

However, this is a solution to the problem in the forehead. First, you see extra rubbish on the screen (moreover, if you have an audio or video file); secondly, the player may stop working with the wrong type of mime.

Consider not solving your current task, but simply outputting to the browser a list of files in a folder: this task can be solved either with PHP, or even without the code at all (setting up an Apache web server is reduced to one line).