百科狗-知识改变命运!
--

ftp_chmod() - ftp函数

是丫丫呀12个月前 (11-21)阅读数 47#技术干货
文章标签权限

ftp_chmod()

(PHP 5, PHP 7)

设置 FTP 服务器上的文件权限

说明

ftp_chmod(resource $ftp_stream,int $mode,string $filename): int

将服务器上的文件权限设置为$mode指定的值。

参数

$ftp_stream

FTP 连接标示符。

$mode

要设置的权限值,八进制值。

$filename

远程文件名称。

返回值

操作成功返回文件新的权限,操作失败返回FALSE

范例

ftp_chmod() - ftp函数

ftp_chmod()函数例程

参见

  • chmod()改变文件模式
Using the excellent octdec and decoct functions you can make this easy: 
Just wanted to contribute a quick note for those who are still experiencing issues with changing the permissions via FTP.
If you are having trouble with PHP recognizing the mode as an integer, you can take the previous poster's method:
$mode = octdec ( str_pad ( $mode, 4, '0', STR_PAD_LEFT ) );
And add the following snippet right after:
$mode = (int) $mode;
This will force PHP to recognize the mode as an integer when you do:
ftp_chmod ( $conn_id, $mode, $path );
These together never seem to fail for me.
It took me a while to figure out how to use this function in my situation because I needed the $mode to be passed to this function as a variable that was read from a database. Since the database returns the value as an integer without a leading zero, I could not get the operation to work because adding a leading zero in PHP turns the value into a string.
For example, this does not work in my situation: 

Adding a leading zero doesn't work either:

I tried many ways to get it to work even converting it from oct to dec using octdec and then back to decoct and nothing worked. This is the only way I was able to get it to work, with an eval statement.
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)