dongxing8650 2018-03-23 11:13
浏览 35
已采纳

从.env变量向PHP mkdir添加八进制位

I have an issue that when I try to load a permission string from my .env file in Laravel and then when I try to use it as an int for the file mode arg in mkdir it deletes the octal bit 0 and as a result the mkdir call gets messed up:

mkdir($this->bakDir, 0755);

Works fine.

echo(\Config::get('app.dbBackupDirPerms')); echo(intval(\Config::get('app.dbBackupDirPerms')));

mkdir($this->bakDir, intval(\Config::get('app.dbBackupDirPerms')));

0755

755

Creates the directory but with the incorrect permissions

Passing \Config::get('app.dbBackupDirPerms'); as a string also doesn't work to my surprise, I figured it would not be type checked by mkdir

Is there anyway around this, am I missing something here? Relatively new to PHP, but I imagine this must be a relatively common occurrence.

  • 写回答

1条回答 默认 最新

  • douzepao0281 2018-03-23 12:53
    关注

    you need to convert your int to octal

    mkdir($this->bakDir, intval(\Config::get('app.dbBackupDirPerms'), 8 )); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图