我想知道我做错了什么.我在PATH里面,我想在PATH里面创建一个文件夹.我想检查文件夹是否已经存在,如果没有,则创建一个.从名称为"dirname"的输入字段中获取文件夹的名称.
if (isset($_POST['createDir'])) {
//get value of inputfield
$dir = $_POST['dirname'];
//set the target path ??
$targetfilename = PATH . '/' . $dir;
if (!file_exists($dir)) {
mkdir($dir); //create the directory
chmod($targetfilename, 0777); //make it writable
}
}
Run Code Online (Sandbox Code Playgroud)
the*_*sin 10
确保您正在处理的目录确实是一个目录可能是个好主意.此代码有效......可根据需要进行编辑.
define("PATH", "/home/born05/htdocs/swish_s/Swish");
$test = "set";
$_POST["dirname"] = "test";
if (isset($test)) {
//get value of inputfield
$dir = $_POST['dirname'];
//set the target path ??
$targetfilename = PATH . '/' . $dir;
if (!is_file($dir) && !is_dir($dir)) {
mkdir($dir); //create the directory
chmod($targetfilename, 0777); //make it writable
}
else
{
echo "{$dir} exists and is a valid dir";
}
Run Code Online (Sandbox Code Playgroud)
编辑:评论是一个很好的暗示;)
| 归档时间: |
|
| 查看次数: |
10099 次 |
| 最近记录: |