Pergunta

This is strange, sometimes works, sometimes it doesnt.

I've put var_dumps of the link()'s arguments.

string(35) "/printbox/web/repo/docusearch/5.pdf"
string(82) "/printbox/web/repo/hardlink/Oleaginosa Moreno Hnos. S.A._20130715_000532989552.pdf"

__

A PHP Error was encountered

Severity: Warning

Message: link(): Operation not permitted

Filename: controllers/ct_form_procesar_escaneos.php

Line Number: 178

__

string(35) "/printbox/web/repo/docusearch/6.pdf"
string(77) "/printbox/web/repo/hardlink/MOLINOS RIO DE LA PLATA_20130715_000533396947.pdf" //THIS WORKED !!!

__ ABOVE WORKED (No error here and in fact hard link was created)

string(35) "/printbox/web/repo/docusearch/7.pdf"
string(77) "/printbox/web/repo/hardlink/RENOVA TIMBUES VICENTIN_20130715_000533520657.pdf"

__

A PHP Error was encountered

Severity: Warning

Message: link(): Operation not permitted

Filename: controllers/ct_form_procesar_escaneos.php

Line Number: 178

I really can't find any pattern.... and when I make a script to manually test one of the previous, also fails:

<?php 
echo "Hi";
link( '/printbox/web/repo/docusearch/7.pdf', '/printbox/web/repo/hardlink/RENOVA TIMBUES VICENTIN_20130715_000533520657.pdf');
?>

Apache's log:

[Mon Jul 15 13:41:57 2013] [error] [client 192.168.100.204] PHP Warning:  link(): Operation not permitted in /printbox/web/repo/a.php on line 3

Striping spaces for _ in the destination name didn't help.

Thanks!

Foi útil?

Solução

Well, seems that the problem is that it needs write permissions on the first file (the one that exists), I don't know why.

Outras dicas

For my situation, I found the following additional steps were required because I regularly update particular tarballs for download by other people, and I create individual hard links in PHP to those tarballs for each HTTP client so that the URL is randomized. In other words, I dynamically create a different hard link in PHP for each visitor to the web site. This failed when I moved from an old OS to a newer OS (OpenSuSE 13.1). Here is my method.

  1. Make the parent directory of the link() target have permission chmod u=rwx,g=rxs,o=rx. This should show up in "ls" as "drwxr-sr-x". In this case, the user.group ownership is wwwrun.www.
  2. Upload the tarball files to the server with permission chmod u=rw,g=rw,u=r. Then these files will inherit the group ownership "www" from the parent directory.
  3. Create multiple hard links in PHP with link() from another directory which is owned by user.group=wwwrun.www to the target files. This is permitted because the file is writeable by group "www", and the group ownership is inherited from the parent directory.

The advantage of this method is that the files can be owned by an ordinary user, but the "www" group can modify the files, and the HTTP server is able to make the hard links because they are group writeable. The user uploading the files to the server does not need to be in the HTTP server's group because of the "BSD semantics" of the group ownership inheritance. (See man 2 stat.)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top