tags:

views:

47

answers:

2

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?

+3  A: 

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.

wojo
done! thanks!!!!
Patrick
+1  A: 

If name of the file is fixed then

  • create a empty file on server
  • set its permission.
  • open it from php
Xinus