anand
anand

Reputation: 1751

Writing to a particular directory not happening in Ubuntu 12.04

I am able to write the data to a /tmp directory in Ubuntu but for other directories like writing to /var directory or Desktop, I am unable to write the contents. Is it a permission issue or something else since I am able to edit, modify and read any file from these directory but while writing through PHP code only in /tmp directory I am able to write.

My code is as follows:

 $output = "/tmp/image5.png";
 //$output = "/home/anand/Desktop/image5.png"

 file_put_contents($output, curl_exec($request));

The second $output is not working.

Upvotes: 0

Views: 161

Answers (1)

dkasipovic
dkasipovic

Reputation: 6120

It is the permission issue. Imagine what would happen if everyone could write in everyone's folders. Or delete from them.

You cannot write to your desktop from your PHP script because php script does not have write permission, since it is running from apache user (www-data probably).

You can write to /tmp directory because those files are stored only temporary and everyone can write to that folder.

If you want to write to particular folder (/home/anand/Desktop/ for example), you need to either chown it to www-data (not recommended for your desktop folder), or use chmod 777 /home/anand/Desktop to give write permission to everyone (also not recommended since then other users will be able to write to your Desktop).

Upvotes: 1

Related Questions