帮助!
因此,我已经在堆栈溢出的情况下看到了许多解决方案,但似乎没有奏效。所以我要做的是创建一个随机数的目录,然后在其中创建一个文本文件。
我的目录是这样的:
localhost
--/tdir/
---/(random number directory) < this is were i want to save to the text file这是我的代码:
<?php
$dir = rand(1, 1999999);
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
if ($dir == true) {
echo "Created directory! :D";
} else {
echo "Failed to create directory! ~ :(";
}
chmod("/tdir/$dir/", 0777);
echo "</br><a href='/tdir/'>Go Back</a>";
echo "</br><a href='/tdir/$dir'>Go to page!</a></br>";
$my_file = '../'.$dir.'/file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
$data = 'This is the data';
fwrite($handle, $data);
?>我一直在犯这个错误:
Created directory! :D
Go Back
Go to page!
Cannot open file: ../1320710 *random number directory* /file.txt我需要能够保存到file.txt目录下的$dir目录!
发布于 2013-11-30 09:00:17
您必须计算mkdir函数的响应,只需这样编写它即可。
if (mkdir($dir, 0777, true) === TRUE){
....此外,在写入/读取文件夹时,请确保使用的是系统路径,而不是URL路径。
https://stackoverflow.com/questions/20298355
复制相似问题