脚本是名为myusername /的public_html /项目/ index.php文件如何将PHP中的文件保存到比当前更高的目录?
代码来保存文件:
$filename = $_SERVER['DOCUMENT_ROOT'].'/../data/guestbook.txt';
$filehandle = fopen($filename, 'ab+') or die("<p>Unable to create the file!</p>\n".$filename);
flock($filehandle, LOCK_EX) or die("<p>Unable to lock the file!</p>\n");
fwrite($filehandle, $new_entry) or die("<p>Unable to write to the file!</p>\n");
fclose($filehandle);
出于某种原因,它则fopen失败,文件名是实际上结束了的是字面上/../而不是导航到正确的路径。
怎么办,该怎么办?
您是否检查目录/文件权限以确保您有权访问?我记得写代码几乎可以写入任意位置。 – ashes999 2012-03-25 03:00:08
@ ashes999是的,我可以访问数据目录:/ – antonpug 2012-03-25 03:02:44
$ _SERVER ['DOCUMENT_ROOT']的输出是什么? – 2012-03-25 03:08:15