本文介绍了php:在表单提交上创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我做错了什么.我在PATH中,我想在PATH中创建一个文件夹.我想检查该文件夹是否已经存在,如果不存在,请创建一个.从名称为"dirname"的输入字段中获取文件夹的名称.
I am wondering what I am doing wrong. I'm inside of PATH and I want to create a folder inside of PATH. I want to check if the folder already exists and, if not, create one. Getting the name of the folder from an input field with name of "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
}
}
推荐答案
确保所处理的目录确实是一个目录可能是一个好主意.该代码有效...根据需要进行编辑.
It might be a good idea to make sure that the directory you are handling is indeed a directory. This code works... edit as you please.
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";
}
祝你好运!
评论是一个很好的提示;)
Good luck!
Edited: comment was a good hint ;)
这篇关于php:在表单提交上创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!