HP371 HP371 - 1 year ago 244
PHP Question

readfile return open stream: HTTP request failed! HTTP/1.1 403 Forbidden in php

I have create one function in Codeigniter controller for download file, here is code for that.

function download_example($file_name) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$file_name);

But after download in file show 403 Forbidden error like this.

A PHP Error was encountered

Severity: Warning Message:
readfile(http://example.com/download_example/example.txt): failed to
open stream: HTTP request failed! HTTP/1.1 403 Forbidden
Filename: controllers/controllers.php Line Number: 371

Answer Source

Change to something like:


If it is local file and current PHP script's directory is same as download_example directory. Change to match your system. Also make sure that file does exists and that user where web server is running has permission to access this file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download