Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP创建文件夹_Php_File_Directory - Fatal编程技术网

使用PHP创建文件夹

使用PHP创建文件夹,php,file,directory,Php,File,Directory,我们可以用PHP代码创建文件夹吗?我希望每当一个新用户创建他的新帐户时,他的文件夹会自动创建,并且还会创建一个PHP文件。这可能吗?您可以使用函数用PHP创建目录 mkdir(“/path/to/my/dir”,0700) 您可以使用模式w在该目录中创建文件 fopen('myfile.txt','w') w:仅用于书写;将文件指针放在文件的开头,并将文件截断为零长度。如果文件不存在,请尝试创建它 。。。然后,您可以使用复制PHP文件,尽管这听起来效率极低。您可以轻松创建它: $structur

我们可以用PHP代码创建文件夹吗?我希望每当一个新用户创建他的新帐户时,他的文件夹会自动创建,并且还会创建一个PHP文件。这可能吗?

您可以使用函数用PHP创建目录

mkdir(“/path/to/my/dir”,0700)

您可以使用模式
w
在该目录中创建文件

fopen('myfile.txt','w')

w:仅用于书写;将文件指针放在文件的开头,并将文件截断为零长度。如果文件不存在,请尝试创建它


。。。然后,您可以使用复制PHP文件,尽管这听起来效率极低。

您可以轻松创建它:

$structure = './depth1/depth2/depth3/';
if (!mkdir($structure, 0, true)) {
die('Failed to create folders...');
}

在回答如何在PHP中写入文件的问题时,可以使用以下示例:

    $fp = fopen ($filename, "a"); # a = append to the file. w = write to the file (create new if doesn't exist)
    if ($fp) {
        fwrite ($fp, $text); //$text is what you are writing to the file
        fclose ($fp);
        $writeSuccess = "Yes";
        #echo ("File written");
    }
    else {
    $writeSuccess = "No";
    #echo ("File was not written");
    }
纯粹的基本文件夹创建
看看这一点:使用
mkdir
是可能的-但你所做的任何事情在很多方面听起来都是“错误的”3)三重威胁=
mkdir
-哦,把Stevie搞混了。现在谈谈“双重麻烦”或什么。呵呵,thnx很多…它解决了所有问题。现在告诉hoe用php代码创建php文件?来吧,伙计,你可以用谷歌搜索这个。它不会杀了你。税务部门会处理的。用例子告诉我整个脚本。Thnx in advancethnx我解决了所有问题。你能告诉我如何使用PHP代码创建文件吗?到目前为止,这是给出的最佳“答案”。我没有Skype,抱歉。好了,它创建了文件夹,现在我如何在由PHP代码在单个文件中创建的文件夹中创建文件。@ShikhilBhalla完全正确。这些是创建文件和文件夹的纯粹基本示例。通过我为您提供的链接,可以在PHP.net上看到更多示例/选项。欢呼(和平)
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
<?php

// change the name below for the folder you want
$dir = "new_folder_name";

$file_to_write = 'test.txt';
$content_to_write = "The content";

if( is_dir($dir) === false )
{
    mkdir($dir);
}

$file = fopen($dir . '/' . $file_to_write,"w");

// a different way to write content into
// fwrite($file,"Hello World.");

fwrite($file, $content_to_write);

// closes the file
fclose($file);

// this will show the created file from the created folder on screen
include $dir . '/' . $file_to_write;

?>