Question

I'm using PHP to retrieve some Base64 data, decode it and write it to a file, my code works fine. However, the owner is apache and the permissions are very low, so even if I FTP into the area where it's uploaded, i cannot download the file. However do i change the permission and owner so i have more control over the file? Here is my code

$path = "uploads/";
$filename = time().".png";
$full_path = $path.$filename;

$image_encoded = $_POST['image'];
$image_decoded = base64_decode($image_encoded);

$handle = fopen($full_path, 'x+');
fwrite($handle, $image_decoded);
fclose($handle);
Was it helpful?

Solution

The superuser and the files' owner can change the owner with:
chown ( string $filename , mixed $user )

The files' permissions can be changed using:
chmod ( string $filename , int $mode )

Plese note you need to use octal notation for the files' permissions, string notation as in Unix won't work! To grant the files' owner every permission, and to allow the other users to be able to read (download) it, the permisison in octal notation is: 0744

See Wikipedia for more information about the octal notation of file permissions.

OTHER TIPS

you might want to use chmod to change file permissions.

Perhaps you are not entitled to download it... You may change it's permissions to 755 or something...

chmod($full_path, 0755);
$handle = fopen($full_path, 'x+');
//...

http://www.php.net/manual/en/function.chmod.php

You should be able to change it's permissions because the file was created by php(the owner)...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top