未创建文件夹

时间:2015-12-17 05:37:20

标签: php

我正在尝试从提交的表单中获取字段/名称并从中创建一个文件夹,它似乎没有错误,但它不会创建文件夹。

我的HTML:

<form id="roomcreation" name="roomcreation" method="post" action="/">
<input type="hidden" name="form_name" value="roomcreation"><p>
Room Name:<p>
<input class="roomcreation_text" name="roomname" type="text" id="roomname";">
<p>File Name:<p>
<input class="roomcreation_text" name="filename" type="text" id="filename";">
<p>Editor Password:<p>
<input class="roomcreation_text" name="editorpassword" type="password" id="editorpassword";"><p>
<p>Genre Select:<p>
  <select name="genre" id="genre" onChange="javascript:chgAction()">
  <option value="" selected="selected">Select</option>
  <option value="Creative">Creative</option>
  <option value="Erotic">Erotic</option>
  <option value="Fantasy">Fantasy</option>
  <option value="Gorean">Gorean</option>
  <option value="History">History</option>
  <option value="Reality">Reality</option>
  <option value="Supernatural">Supernatural</option>
  <option value="Transilient">Transilient</option>
  </select>

<?php echo $error_message; ?><p>

<input class="roomcreation_button" type="submit" name="create" value="Create Room" id="roomcreate";">
</form>

我的php:

<?php
// 
if (isset($_POST['filename']) && isset($_POST['editorpassword']) && isset($_POST['roomname']))

$dir  = $_POST['filename']; // This must match the "name" of your input
$path = "evo/$dir";
if (!file_exists('$path')) {
mkdir('$path', 0755, true);
}

print_r($_POST); exit; //

?>

更新

我更改了我尝试输出的目录,与脚本当前所在的目录相同,evo / $ dir并且它插入了一个名为$ path的文件夹,这意味着它没有获取文件名变量而且因为我有它以前写过它不写入我想要去的目录,即/ rooms / creative / $ dir。

2 个答案:

答案 0 :(得分:1)

$path = rooms/creative . '/' . $dir;

替换为:

$path = "rooms/creative/$dir";  

答案 1 :(得分:1)

<强>表格

<form id="roomcreation" name="roomcreation" method="post" action="">
    <input type="hidden" name="form_name" value="roomcreation">
    <p>
        Room Name:
        <input class="roomcreation_text" name="roomname" type="text" id="roomname">
    </p>
    <p>
        File Name:
        <input class="roomcreation_text" name="filename" type="text" id="filename">
    </p>
    <p>
        Editor Password:
        <input class="roomcreation_text" name="editorpassword" type="password" id="editorpassword">
    </p>
    <p>
        Genre Select:
        <select name="genre" id="genre" onChange="javascript:chgAction()">
            <option value="" selected="selected">Select</option>
            <option value="Creative">Creative</option>
            <option value="Erotic">Erotic</option>
            <option value="Fantasy">Fantasy</option>
            <option value="Gorean">Gorean</option>
            <option value="History">History</option>
            <option value="Reality">Reality</option>
            <option value="Supernatural">Supernatural</option>
            <option value="Transilient">Transilient</option>
        </select>
    <p>
    <?php echo $error_message; ?><p>
        <input class="roomcreation_button" type="submit" name="create" value="Create Room" id="roomcreate">
</form>

服务器端脚本

<?php
if (isset($_POST['filename']) && isset($_POST['editorpassword']) && isset($_POST['roomname'])) {
    $dir = $_POST['filename']; // This must match the "name" of your input
    $path = "evo/" . $dir;
    if (!file_exists($path)) {
        mkdir($path, 0755, true);
    }
}
?>

<强>输出

enter image description here

尝试此操作,如果没有工作更改权限0777(请注意,0777已经是目录的默认模式,可能仍会被当前的umask修改。)

我希望这会有所帮助。

如果您不确定路径,请使用dirname(__FILE__)