php 无法打开流:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16934912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
failed to open stream: No such file or directory
提问by
Can anyone help with this one? I am new to web developing and not sure what this error means?
任何人都可以帮助解决这个问题吗?我是 Web 开发新手,不确定此错误意味着什么?
Warning: fopen(images/nophoto.png): failed to open stream: No such file or directory in /home/u835626360/public_html/remove.html on line 101
警告:fopen(images/nophoto.png):无法打开流:第 101 行的 /home/u835626360/public_html/remove.html 中没有这样的文件或目录
can't this file/picture is open you need close
无法打开此文件/图片,您需要关闭
CODE:
代码:
$expire=time()-3600;
setcookie("dname","a", $expire);
setcookie("dpode","a", $expire);
}
function delpics($filename)
{
$path_to_file='userpics/';
$old = getcwd(); // Save the current directory
chdir($path_to_file);
$fh = fopen($filename, 'w') or die("can't this file/picture is open you need close ");
fclose($fh);
if (!unlink($filename))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $filename");
}
chdir($old); // Restore the old working directory
}
回答by Burhan Khalid
You need to give fopen
the full path of the file, and you don't need chdir()
at all. Try this version:
您需要提供fopen
文件的完整路径,而您根本不需要chdir()
。试试这个版本:
$path_to_file='userpics/';
$fh = fopen($path_to_file.$filename, 'w') or die('Permission error');
回答by Jebik
First make the dir manually in your server(if you have one) or local pc(if you dev in local)
首先在您的服务器(如果您有)或本地电脑(如果您在本地开发)中手动制作目录
Be sure to have write right for apache in your dir (0777 in unix-linux if you wan't to be sure you can do what you wan't and no idea for windows)
确保在你的目录中为 apache 写正确(如果你不想确定你可以做你想做的事情并且不知道 windows 的想法,则在 unix-linux 中为 0777)
and then like it was said give the good path to fopen and not only filename
然后就像据说给 fopen 而不仅仅是文件名的好路径
回答by Gimmy
Try this:
尝试这个:
$expire=time()-3600;
setcookie("dname","a", $expire);
setcookie("dpode","a", $expire);
function delpics($filename)
{
$path_to_file='/userpics/';
$old = getcwd(); // Save the current directory
chdir($old.$path_to_file);
$fh = fopen($filename, 'w') or die("can't this file/picture is open you need close ");
fclose($fh);
if (!unlink($filename))
{
echo ("Error deleting $file");
}
else
{
echo ("Deleted $filename");
}
chdir($old); // Restore the old working directory
}
回答by Yash
I was facing same problem. I was thinking file will be created if I use w or w+ but giving me above error.
我面临同样的问题。我想如果我使用 w 或 w+ 会创建文件,但是给了我上面的错误。
So problem was we need to create dir before we can create file.
所以问题是我们需要先创建目录才能创建文件。
We can get absolute DIR path of file
我们可以获得文件的绝对 DIR 路径
$dir = dirname($filename);
Create DIR
创建目录
//if(!is_dir($dir))
mkdir( $dir , 0755, true);
Third parameter is important you want recursively
第三个参数很重要,你想要递归
I know it sound stupid but it may save someone's time so added here
我知道这听起来很愚蠢,但它可能会节省某人的时间,所以在这里添加