-1

私が持っているサンプル ディレクトリからファイルを追加する方法がよくわかりません。助けていただければ幸いです。ユーザーがユーザー名を入力するたびに新しいディレクトリを正常に作成しましたが、内容は空です。

編集: 目的のディレクトリ構造を作成しました。サンプル テンプレートにあるページを含める/コピーするだけです。

<?php
     $fileName = "/associate/sample/";

    $Name = $_POST['name'];

    $thisdir = getcwd();

    $folderPath = $thisdir . '/' . $Name;

    mkdir($folderPath);

    chmod($folderPath, 0777);

    file_put_contents (realpath("$fileName"), associate/$Name);

    ?>
4

1 に答える 1

2

あなたは近づいていましたが、それを正しく行っていませんでした。これを見て、あなたが持っているものと比較して、私が違うことをしたことを確認してください

$folder = "/associate/";
$name = 'Joshua';
$thisdir = getcwd();
$folderPath = $thisdir . $folder . $name;
$filename  = $name.'.file';
if(!file_exists($folderPath)){
  mkdir($folderPath);
  chmod($folderPath,0777);
}
$textToWrite = 'this is some text';
file_put_contents(realpath($folderPath).'/'.$filename, $textToWrite);
于 2015-09-03T03:43:57.260 に答える