Taking quotes off in downloading a file

<?php

$filepath = 'target.php';
$filesize = filesize($filepath);
$path_parts = pathinfo($filepath);
$filename = $path_parts['basename'];
$extension = $path_parts['extension'];

header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='$filename'");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $filesize");

ob_clean();
flush();
readfile($filepath);

The code above makes download a file “target.php” which is in the same directory.

As I check it, “target.php” is downloaded with the name the quote below.
actual downloaded file name

I expected “target.php” is downloaded with the name the quote below.
target download file name

How can I make it downloaded with taking the single quote and double quote off before and after the file name “target.php”?

The doc suggests that you should surround the filename with double-quotes, but you are surrounding it with single-quotes. Perhaps that is causing the problem. So, build the header string with double-quotes around the name, and see if that helps.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.