Im generating a file to present to the user for download, but the server isnt letting me open it, because it needs to have permissions of 777 before it can do so.
Here is my code
$fh = fopen("$name", 'w') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Length: ". filesize("$name").";");
header("Content-Disposition: attachment; filename=$name");
header("Content-Type: application/octet-stream; ");
header("Content-Transfer-Encoding: binary");
readfile($name);
any way to set the permissions of this before before i open it, or how would i go about doing this? The file has not been created yet, so开发者_开发问答 it might be kind of a endless loop. Should i make the file, then open it, or what?
If you don't need the temporary file you're writing, $name, then just stream it right out without creating a file at all.
You can instead just output all your headers and echo the output.
If name of the file is fixed then
- create a empty file on server
- set its permission.
- open it from php
精彩评论