PHP chmod() and umask() not functioning

1.7k views Asked by At
$url = 'http://gdata.youtube.com/feeds/api/playlists/blabla';
$fp = fopen($url, 'r'); 
$buffer='';
if ($fp) {
while (!feof($fp))
$buffer .= fgets($fp, 1024);
fclose($fp);
$buff=stripslashes($buffer);
$old = umask(0); 
file_put_contents("si.xml", $buff);
chmod("si.xml", 0777);
umask($old);

The warnings I get are

Warning: file_put_contents(si.xml) [function.file-put-contents]: failed to open stream
Warning: chmod() [function.chmod]: Permission denied 

I've even manually set entire directory file permissions to 777, but no use.
Am using filezilla on windows

1

There are 1 answers

9
paxdiablo On

They are working, they're just irrelevant here :-)

Write permissions on the directory (and 777 is a bad idea by the way) give you the right to create, rename and delete files in that directory.

If you want to write to the files that are already there, it's the permissions on the file that matter, not the directory.

From the errors, it looks like si.xml already exists and it's protected from you. With write permissions on the directory, you could first delete the file that's there then recreate it, but you're probably better off fixing the permissions on the file itself.