开发者

Difficulty Creating New Directory for Upload in 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 ru开发者_运维技巧n 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.


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜