Domanda

I'm trying to save some text that comes into a php script via a POST to a file. Here is my script:

<?php

$path = $_SERVER['DOCUMENT_ROOT'];
$file = $path . '\test.txt';

$text = $_POST['text'];

// save it to a file
if (file_exists($file))
    chmod($file, 0777);

$handle = fopen($file, 'w');
fwrite($handle, $text);
fclose($handle);

echo "success";

?>

I'm getting this error:

Warning: fopen(D:\Hosting\11347607\html\test.txt) [function.fopen]: failed to open stream: Permission denied in D:\Hosting\11347607\html\test_file_saver.php on line 12

I've tried a number of different attempts and read many posts. The directory is set to RWX permission. How can I get permission to write to this file? Thanks!

È stato utile?

Soluzione

If you don't have permissions to even open the file, what makes you think you have permission to change permissions?

That wasn't a question or a comment. You don't have permission to change the permission. Give your PHP process proper permissions.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top