简体   繁体   English

无法打开流:没有这样的文件或目录

[英]failed to open stream: No such file or directory

Can anyone help with this one? 任何人都可以帮助这个吗? I am new to web developing and not sure what this error means? 我是网络开发的新手,不知道这个错误意味着什么?

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   
}

You need to give fopen the full path of the file, and you don't need chdir() at all. 你需要给fopen文件的完整路径,你根本不需要chdir() Try this version: 试试这个版本:

$path_to_file='userpics/';
$fh = fopen($path_to_file.$filename, 'w') or die('Permission error');

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   
     }

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. 所以问题是我们需要在创建文件之前创建dir。

We can get absolute DIR path of file 我们可以获得文件的绝对DIR路径

$dir = dirname($filename);

Create DIR 创建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 我知道这听起来很愚蠢,但它可能会节省一些人的时间

First make the dir manually in your server(if you have one) or local pc(if you dev in local) 首先在服务器中手动创建目录(如果有的话)或本地pc(如果你在本地开发)

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) 一定要在你的dir中为apache写一个权利(unix-linux中的0777,如果你不确定你能做什么你不想做什么,不知道windows)

and then like it was said give the good path to fopen and not only filename 然后就像它说的那样给fopen提供了良好的途径而不仅仅是文件名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM