[英]PHP - fopen: failed to open stream: Permission denied
I'm new to PHP. 我是PHP新手。 I planned to create folder, sub folder, into that file depends on user Input.
我计划根据用户输入将文件夹创建为子文件夹。
Folder and sub folders has been created successfully. 文件夹和子文件夹已成功创建。
Finally I try to create a file its showing bellow error. 最后,我尝试创建一个文件,显示波纹管错误。
fopen(upload/localhost/hrms): failed to open stream: Permission denied in C:\\xampp\\htdocs\\ssspider\\index.php on line 205
fopen(upload / localhost / hrms):无法打开流:205行的C:\\ xampp \\ htdocs \\ ssspider \\ index.php中的权限被拒绝
My code is: 我的代码是:
$dir = "http://localhost:8080/hrms/index.php";
//make directory
$directoryForServer = "upload";
$directoryForClient = $directoryForServer."/".$host."";
mkdir($directoryForClient);
$splitePath = explode("/", $folderPath);
$folderPath1 = $directoryForClient;
for($x = 1; $x <= (count($splitePath)-1) ; $x++)
{
$folderPath1 = $folderPath1."/".$splitePath[$x];
echo "<br>".$folderPath1." - successfully created<br>";
mkdir($folderPath1);
}
writefile($folderPath1);
function writefile($dir)
{
if( is_dir($dir)){
echo $dir;
$myFile = fopen($dir,"w");
if($myFile)
{
fwrite($myFile, $returned_content);
}
fclose($myFile);
}
}
Please help me to find out my problem? 请帮我找出问题所在吗?
Edit: Thanks. 编辑:谢谢。 I got an error.
我有一个错误。 In fopen I didn't mention file name .
在fopen中,我没有提到文件名。 Now its working fine.
现在它的工作正常。 Thanks
谢谢
because you open a directory , fopen function just open file. 因为打开目录,所以fopen函数只打开文件。 your code is fill with error , just Refer to the following:
您的代码充满了错误,只需参考以下内容:
<?php
//make directory
$host = "aa"; //define $host variable
$directoryForServer = "upload";
$directoryForClient = $directoryForServer."/".$host."";
@mkdir($directoryForClient);
$splitePath = explode("/", $directoryForClient);
$folderPath1 = $directoryForClient;
for($x = 1; $x <= (count($splitePath)-1) ; $x++)
{
$folderPath1 = $folderPath1."/".$splitePath[$x];
echo "<br>".$folderPath1." - successfully created<br>2";
@mkdir($folderPath1);
}
writefile($folderPath1);
function writefile($dir)
{
if( is_dir($dir)){
echo $dir;
$myFile = fopen("upload/aa.txt","w");
if($myFile)
{
$returned_content = "hello world"; //define variable and his content before write to file.
fwrite($myFile, $returned_content);
}
fclose($myFile);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.