0

我正在使用 PHP 检索一些 Base64 数据,对其进行解码并将其写入文件,我的代码工作正常。但是,所有者是 apache,权限非常低,所以即使我 FTP 到它上传的区域,我也无法下载文件。但是我是否更改了权限和所有者,以便我对文件有更多的控制权?这是我的代码

$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);
4

2 回答 2

1

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.

于 2011-09-30T10:50:28.283 回答
1

您可能想使用 chmod 更改文件权限。

也许您无权下载它...您可以将其权限更改为 755 或其他东西...

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

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

您应该能够更改它的权限,因为该文件是由 php(所有者)创建的...

于 2011-09-30T10:41:41.617 回答