如何在我想要使用php的目录中的服务器上创建文件?我找到了函数fopen
,但它对我没用,因为我们无法选择目录。
示例:
$href = '/contact/downloads/227856/file2.php'
if (file_exists($href)) {
echo "File exists";
} else {
echo "File doesn't exist, but we will create it";
// And there we gonna create the file in the directory $href
}
答案 0 :(得分:0)
$path_to_file = " " //Make sure $path_to_file is the full path, something like /home/user/public_html/etc/ <br>
$yourFileName = 'myfile';
$ourFileHandle= fopen($path_to_file.$yourFileName, 'w') or die('Permission error');