我想使用PHP创建一个文件夹,其名称基于HTML表单的输入值。
Μyhtml代码如下:
<input name="foldername" id="foldername" >
虽然我的PHP如下:
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
}
}
我的代码似乎无法正常运行。我做错了什么?
答案 0 :(得分:3)
您输入的名称是“foldername”,但在PHP中您引用的是“dirname” - 这些名称必须相同。
答案 1 :(得分:1)
<?php
// You are passing in a hidden field or something for this, right?
if (isset($_POST['createDir']) and ! empty($_POST['foldername'])
{
$dir = $_POST['foldername']; // This must match the "name" of your input
$path = PATH . '/' . $dir;
is_dir($path) or mkdir($path, 0777, true);
}
print_r($_POST); exit; // just so we can help you debug a little...