Mustafa Shujaie
Mustafa Shujaie

Reputation: 816

php://ouput is not valid

I am going to generate a csv file to php output, so the user can download it immediately:

header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment; filename=' . $filename );
$fp = fopen('php://ouput', 'w'); // Here is where error happens, line 156
if(!$fp) var_dump($fp); // output: bool(false)

but it produces the below errors:

Warning: fopen(): Invalid php:// URL specified in /home/mustafa/xxx/includes/functions.php on line 156
Warning: fopen(php://ouput): failed to open stream: operation failed in /home/mustafa/xxx/includes/functions.php on line 156

Why php://output is not valid

Upvotes: 2

Views: 414

Answers (2)

Veger
Veger

Reputation: 37915

fopen() write to a file. php://ouput is no a valid filename/URL. It is php://output, you are missing a 't'.

If you want to send your output to the client (browser), just print the data with echo.

Upvotes: 1

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

change this

$fp = fopen('php://ouput', 'w');

to

$fp = fopen('php://output', 'w');
                     ^ // you missed `t`

Upvotes: 2

Related Questions