0

I have to start a download with php of a file inside a password protected folder.

I have the following code:

<?php
$File="https://testuser:password@www.testdomain.com/test/2/file.zip";
if(file_exists($File))
{
    header("Content-Disposition: attachment; filename=\"" . basename($File) . "\"");
    header("Content-Type: application/octet-stream");
    header("Content-Length: " . filesize($File));
    header("Connection: close");
    readfile($File);
}
?>

file_exists and filesize seems that don't work with this kind of url. How can I solve the problem?

Border
  • 15
  • 3
  • Each time you pass a URL to a function that needs to see the content, it will download the file all over again. Download the file contents first, into a local file or just a string; then do whatever you like with it. – IMSoP Jul 10 '22 at 18:52
  • Is this password protected folder under a different domain? If not, and you are working within the same host setup on the same server - then you should read the file content via the file system to begin with, and not via HTTP. – CBroe Jul 11 '22 at 06:50

0 Answers0