如何在特定目录中创建文件?
这是我目前的代码:
$username = $_POST["username"];
$filedir = "./u/".$username;
mkdir($filedir);
$folder = $filedir;
chmod($filedir, 0777);
$createfile = fopen( $_SERVER['DOCUMENT_ROOT'] . '/path/filename.php' );
我有点!!!这是
$createfile = fopen('./u/'.$username.'/'.$username.'.php', 'x');
答案 0 :(得分:2)
模式必填。指定文件/流所需的访问类型。
fopen(filename,mode)
$createfile = fopen($_SERVER['DOCUMENT_ROOT'] . '/path/filename.php',"r"); // read only
可能的值:
答案 1 :(得分:2)
答案是这样的:
yuv420p

答案 2 :(得分:0)
您可以尝试使用这些功能 - 一个递归创建文件夹路径,另一个将在指定路径中创建一个空文件。
/* recursively create folder path */
function createdir( $path=null, $perm=0644 ) {
if( !file_exists( $path ) ) {
createdir( dirname( $path ) );
mkdir( $path, $perm, true );
clearstatcache();
}
}
/* create an empty file ensuring that path is constructed */
function createfile( $path=false, $filename=false ){
if( $path && $filename ){
createdir( $path );
file_put_contents( $path . DIRECTORY_SEPARATOR . $filename, '' );
return true;
}
return false;
}
$dir=$_SERVER['DOCUMENT_ROOT'] . '/path/to/dir';
$filename='geronimo.txt';
$result=call_user_func('createfile', $dir, $filename );
答案 3 :(得分:0)
对于那些来这里的人,我想变得更加明显:
“如何在PHP中的特定地址中创建文件”
<pre><code>
----------begin_max5_patcher----------
1298.3ocyZszaiaCD9r8uBBcYu3FPQQIQ0doONs.s25s0EAzVLILURzPjJO5
h8+dGQIk0OnikroSq.br0HZNb9373anyWmOKXk5EgN.8inuflM6qymMyJpUv
r96mETxeYcAWaGVvZUYonxDrn6YFwKFq7em+pnVVcOx7rBUKtW7xF3sR0SBM
x7f.soVrVHxaGgdCes.DxM1mbmrVaP77b8vjVHqDqUMU1Yl1KDl.MnXtQppt
cmQjzOhUMqVUH1njchw2f6ePUSorpPXrVP3v7wMqe.VN2BKLSGBjjvtglAWL
RXHKAmDmt.EEm0ILgQwYwQLBHLDyfYGkB5.8W6ndsLWX0920spwLnb7Vv1iM
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7vVx6pZnS3qfpGiQmE5Vy
3KaiMbLpF6CWnwftdPOrw.lrLOnIng2QnIeXSz3OJMMpf.F8Z3Jt2rdDUm3C
3DOFeQej2jLFmQpOBuhFSfLwGYnIiwYjbnyXWgU9lMOIp08i1pDfZwiJqCDa
g8VYU2sVBA.QzmjCi2R4KfWC7CL.4flZ6BK3kDZP2WE5BqtpQ1mRFLOPkZyq
E6WLuB5iZK1uXbeu8f4bGuovrKFbmpxnk+SOJDtMkz1GMLYfs+K0RdA5WANN
ACF+hdzsFHLYWJV81qtRPWxgXmALxxypcRs+22zcbI.cr4ea9+ZcPc0D
-----------end_max5_patcher-----------
</code></pre>
就是这样。此功能将获取文件的地址和名称(无论您要使用什么名称),并会在该确切地址
中为您创建文件 注意:
对于认为与另一个人的答案相同的人,所以不是,因为我的答案有错误和问题,所以我尝试将function createFile($name, $address){
$createfile = fopen($address.'/'.$name, 'x');
}
和{ {1}},我解决了问题