duanchique1196 2011-07-06 00:42
浏览 16
已采纳

难以在PHP中创建用于上载的新目录

I am using PHP to create a directory. After the directory is created it is given a chmod of 777. I then have a simple script for a user to upload a file to the directory. The issue that I am having is that the directory will not complete the file transfer when I run the script. BUT... if I manually go in via FTP and create a new directory and assign 777 to the generated folder then the script works fine and the file is transferred. Is there some set-up with my web host that is limiting this ability? Or is it in the PHP script? Here is the code wherein I create the new directory:

<?php

$thisdir = getcwd(); 
$new_dir = 'test';
$full_dir = $thisdir . "/" . $new_dir;

function chk_dir($full_dir) {
if(is_dir($full_dir)) {
    echo 'the directory already exists';
} else {
    return mkdir($full_dir);
}

}
chk_dir($full_dir);
chmod($full_dir, 0777);
?>

I know there must be a simple explanation for this, thank you for reviewing my issue.

  • 写回答

1条回答 默认 最新

  • douqian1975 2011-07-06 04:54
    关注

    Check if Safe_mode is turn on on your server.

    mkdir() creates folder as owner, it's not the script owner, so the scripts couldn't upload the file into that folder. While safe_mode is turned on chmod() dosen't work. Doc: http://php.net/manual/en/features.safe-mode.php

    try adding this line at the beginning of the php script to check for warnings:

    ini_set('display_errors', '1');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源