的index.php
<html>
<body>
<form action="createfolder.php" method="post" >
<table width="400" border="0" cellspacing="0" cellpadding="5">
<tr>
<td colspan="3" align="center">Please write gallery name and description</td>
</tr>
<tr>
<td>Name </td>
<td> </td>
<td><input type="text" name="gname" id="text" value=""></td>
</tr>
<tr>
<td>Description</td>
<td> </td>
<td><textarea name="gdescription" cols="30" rows="5" id="textarea"></textarea></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" id="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
createfolder.php
<?php
$name = $_POST['gname'];
$dirPath = "images/".$name;
$result = mkdir($dirPath, 0755);
if ($result == 1) {
echo $dirPath . " has been created";
} else {
echo $dirPath . " has NOT been created";
}
?>
制作目录时遇到问题。错误:
答案 0 :(得分:1)
因为目录用户
中没有文件 file_exists
- 检查文件或目录是否存在且
is_dir
- 判断文件名是否为目录
if (is_dir("path") === true ){
echo "DIRECTORY: ".$entry."\n";
}
或
$filename = '/path/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
}
答案 1 :(得分:0)
mkdir( $dirPath, 0755, true );
第三个参数也会以递归方式创建包含目录。
答案 2 :(得分:0)
mkdir()
有第三个参数$recursive
,它将确保存在完整路径。替换这个:
$result = mkdir($dirPath, 0755);
使用:
$result = mkdir($dirPath, 0755, true);
它应该可以正常工作。