1
$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

krishna
  • 930
  • 1
  • 16
  • 35

1 Answers1

2

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.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • I mean its the way by which I checked all the possibilities to make the script work, to the best of my knowledge. I'd be glad if u can suggest/ write down the corrected code – krishna Jan 31 '12 at 06:52
  • 2
    @pbvamsi: Would you like it by emailz? – Ignacio Vazquez-Abrams Jan 31 '12 at 06:55
  • @pbvamsi: you need write access to the directory if you want to create/delete/rename files (use chmod to set this once, most likely). You need write access to the files you create in order to overwrite them (use umask before creating and/or chmod after creating). The values to use for chmod/umask depend entirely on whether you want access restricted to one user, one group or everyone. – paxdiablo Jan 31 '12 at 06:56
  • @Ignacio Vazquez-Abrams yes please...I'll be waiting...bvkrishna.sgs@gmail.com – krishna Jan 31 '12 at 06:57
  • @paxdiablo no `si.xml` is not existing, I agree 777 is bad idea on directory. however at the final stage it creates an `XML` if already exists it should overwrite the update. – krishna Jan 31 '12 at 07:08
  • @pbvamsi, if the file doesn't exist, and you're not able to create it, you don't have write access to the directory, plain and simple. If you're saying it works with the permission set to 777, then you've solved the problem. If everyone needs to be able to create/delete/rename/overwrite files in that directory then, yes, 777 is acceptable. As long as you're aware people can change other people's files. Maybe that's not a problem in your scenario, I don't know. – paxdiablo Jan 31 '12 at 07:12
  • @paxdiablo its showing the same error and am not able to create the file. Is there any other modified way...if not suggest any changes to my script. Thanks – krishna Jan 31 '12 at 07:19
  • @pbvamsi, do an `ls -ald` and an `ls -al` on your directory, then post the results. – paxdiablo Jan 31 '12 at 07:23
  • @paxdiablo Sry, I use filezilla on windows – krishna Jan 31 '12 at 07:25