To download the file I'm using the GET request to the download server like domain.com/?file=/uploads/files/03/48/51/2017/04/09/file.rar
On my computer, like most users, the download goes well. But for some users (about 10-20% of total), there are errors. From their words (different users):
- In Chrome in download status Network Error: Network Error
- 502 bad gateway
- Download file as php.
- Antivirus block.
-
404 error
function clean($string) { // $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. //$string = preg_replace('/[^A-Za-z0-9\-\.\_]/', '', $string); // Removes special chars. return preg_replace('/\.\./', '', $string); // Replaces multiple hyphens with single one. } function file_force_download($file) { $file = clean($file); if (file_exists($file)) { if (ob_get_level()) { ob_end_clean(); } if ($mimetype = mime_content_type($file)) {} else $mimetype="application/octet-stream"; header('Content-Description: File Transfer'); header('Content-Type:.'.$mimetype); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); if ($fd = fopen($file, 'rb')) { while (!feof($fd)) { print fread($fd, 1024); } fclose($fd); } exit("Error while reading file"); } exit("File does not exist"); } $file = $_GET['file']; $file = preg_replace('/uploads\/files\//', '', $file); if (preg_match("/\d\d\/\d\d\/\d\d\/\d\d\d\d\/\d\d\/\d\d\/.{1,60}/i", $file)) { file_force_download("uploads/files/".$file); } else exit ("Incorrect file link"); ?>
I tried changing the download server and the domain does not help. Why this happens?