【发布时间】:2014-09-09 09:02:39
【问题描述】:
我已使用此代码创建新文件夹我如何使用名称表单客户端输入创建新文件夹,但在第六行出现错误
Warning: mkdir() [function.mkdir]: File exists in /home/a3629462/public_html/123.php on line 6
这是第 6 行出现的错误
$file_path = "uploads/";
$new_name = ""; // this is the new folder you'll create
$file_path .= $new_name . '/';
mkdir($file_path);
chmod($file_path, 0777);
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
echo "success";
} else{
echo "fail";
}
这是我使用的 HTML 表单,我需要使用在标题框中输入的输入文本来创建文件夹名称
<form action="" method="post" enctype="multipart/form-data" name="addroom">
Select Image: <br />
<input type="file" name="uploaded_file" class="ed"><br />
Caption<br />
<input name="caption" type="text" class="ed" id="brnu" />
<br />
<input type="submit" name="Submit" value="Upload" id="button1" />
</form>
【问题讨论】:
-
您知道
$new_name是空的吗?因此,警告是关于uploads/已经存在。 -
$new_name = 在那个地方我需要来自客户端的输入文本
-
不建议在文件操作中直接使用未经审核的用户输入。
标签: php forms directory renaming