Im creating a file for presentation to the user for download, but the server does not allow me to open it, because it must have 777 permissions before it can do it.
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);
somehow set the permissions of this before I open it, or how can I do this? The file has not yet been created, so it can be a kind of endless loop. Should I make a file, then open it or what?
source
share