1

HTMLフォームの入力値に基づいた名前で、PHPを使用してフォルダを作成したいと考えています。

μy html コードは次のとおりです。

<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
    }
}

私のコードは機能していないようです。私は何を間違っていますか?

4

2 に答える 2

3

入力の名前は「foldername」ですが、PHP では「dirname」を参照します。これらは同じである必要があります。

于 2013-03-08T00:01:24.527 に答える
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...
于 2013-03-08T00:23:24.680 に答える