apache / php dosyası oluşturur, ama aynı sayfa dosyasını düzenlemek için izin verilmez

1 Cevap php

Ben benim test üzerine hareket eden bir sorun haline çalıştırmak (ve eşya üzerinde denedim, no go) Ben bir php komut dosyası var bir dosya oluşturun ve bu dosyaya bazı verileri koymak.

Ben R, W, X izinleri kurdum "Owner, Grup Diğer" WinSCP kullanarak (ben henüz komut için çok değilim).

What i can see is that the script is able to create the file (i've deleted, and it recreates the files properly every time), but the exact same script can't write to the file and I get a permission error. "failed to open stream: permission denied"

İşte kullanıyorum script, bu pencereler çalıştı, ama şimdi linux üzerinde, gitmek yok.

Herhangi bir fikir?


$type='get';

$count_my_page = ("list".$counterDate.".txt");
if(!file_exists($count_my_page)){
$fp=fopen($count_my_page, "w");
$putArray=array($type=>'1');
$putJson=json_encode($putArray);
fputs($fp, $putJson);
fclose($fp);
} else {

$hits = file($count_my_page);
if(empty($hits)){
    $putArray=array($type=>'1');
$putJson=json_encode($putArray);

} else {
    $putArray=json_decode($hits[0], true);
    if(!array_key_exists($type, $putArray)){
    	$putArray[$type] = '1';


    } else {

    	$hit=$putArray[$type];

    	$putArray[$type]++;

    }
}
$putJson=json_encode($putArray);
$fp=fopen($count_my_page, "w");
fputs($fp, $putJson);
fclose($fp);

}

1 Cevap

Bir dosya oluşturma dizinde yazma izni gerektiren (that is probably what you set with winscp ?).

But modifying a file requires write permissions on the file itself.
To give such permissions to Apache, you might have to use the function chmod after you're done creating the file.

Böyle bir şey, ben sence olabilir:

chmod($count_my_page, 0666);

6 = 4 (read) + 2 (write).
You don't need to give execution (1) privilegies.

Bu yardımcı olur mu?


And I supposed it worked on windows because Apache run as your user (or as administrator) -- or because Windows' permission system is more permissive


Edit : for more details about permissions under Linux, you might what to take a look at this part of the corresponding Wikipedia article (quoting) :

There are three specific permissions on Unix-like systems that apply to each class:

  • The read permission, which grants the ability to read a file. When set for a directory, this permission grants the ability to read the names of files in the directory (but not to find out any further information about them, including file type, size, ownership, permissions, etc.)
  • The write permission, which grants the ability to modify a file. When set for a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.
  • The execute permission, which grants the ability to execute a file. This permission must be set for executable binaries (for example, a compiled c++ program) or shell scripts (for example, a Perl program) in order to allow the operating system to run them. When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set).


You could also have fun with umask, but I've always prefered calling chmod when it's necessary (and only when it's necessary : I prefer not giving too much permissions -- more secure this way) -- and umask may have some problems with some servers, if I remember correctly