Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Copying file permissions with fileperms and ftp_chmod
    text
    copied!<p>The overall goal: Copy the permissions of files from the local filesystem when uploading them over FTP using PHP.</p> <p>The problem: While ftp_chmod appears to succeed, and according to the print statement in the code I'm setting the right permissions, it sets completely wrong permissions.</p> <p>The code:</p> <pre><code>&lt;?php $perms = fileperms($src); if ($perms !== false) { // We only take the last 3 digits, since we're only interested in 'normal' file permissions, not extended ones. $perms &amp;= 511; $permsm = sprintf('%o', $perms); print "DEBUG: Setting permissions: $perms :: ". decoct($perms) ." :: $permsm :: $dst\n"; ftp_chmod($conn_id, $permsm, $dst); } ?&gt; </code></pre> <p>The result: Source / expected file permissions (local filesystem):</p> <pre> -rw-r--r-- 1 allen users 15572 Jun 2 12:40 Foo.docx -rw-r--r-- 1 allen users 16877 Jun 2 12:40 Bar.docx drwxr-xr-x 2 allen users 4096 Jun 15 14:01 configuration drwxr-xr-x 9 allen users 4096 Jun 15 14:01 content drwxr-xr-x 3 allen users 4096 Jun 15 14:01 local -rw-r--r-- 1 allen users 152274 Jun 11 17:13 foo1.sql -rw-r--r-- 1 allen users 9984 Mar 2 10:44 footest.sql drwxrwxrwx 2 allen users 4096 Jun 15 14:01 tmp drwxr-xr-x 3 allen users 4096 Jun 15 14:01 versions </pre> <p>Destination / actual result file permissions (ftp upload):</p> <pre> --w----r-T 1 ftptest ftptest 15572 Jun 15 14:42 Foo.docx --w----r-T 1 ftptest ftptest 16877 Jun 15 14:42 Bar.docx d-wxrw--wt 2 ftptest ftptest 4096 Jun 15 14:42 configuration d-wxrw--wt 9 ftptest ftptest 4096 Jun 15 14:42 content d-wxrw--wt 3 ftptest ftptest 4096 Jun 15 14:42 local --w----r-T 1 ftptest ftptest 152274 Jun 15 14:42 foo1.sql --w----r-T 1 ftptest ftptest 9984 Jun 15 14:42 footest.sql dr----x--t 2 ftptest ftptest 4096 Jun 15 14:42 tmp d-wxrw--wt 3 ftptest ftptest 4096 Jun 15 14:42 versions </pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload