Could not open stream: no such file or directory

Can anyone help with this? I'm new to web development and not sure what this error means?

Warning: fopen (images / nophoto.png): could not open the stream: there is no such file or directory in / home / u 835626360 / public_html / remove.html on line 101

Unable to open this file / image, you need to 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 } 
+6
source share
4 answers

You need to tell fopen full path to the file, and you don't need chdir() at all. Try this version:

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

Try the following:

  $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 } 
0
source

I had the same problem. I thought a file would be created if I use w or w +, but give me the error above.

So the problem was that we needed to create a directory before we could create a file.

We can get the absolute path of the DIR file

 $dir = dirname($filename); 

Create DIR

 //if(!is_dir($dir)) mkdir( $dir , 0755, true); 

The third parameter is important, you want to recursively

I know this sounds silly, but it can save the time added here.

0
source

First create the directory manually on your server (if you have one) or on the local computer (if you are working on the local network)

Be sure to write the right for apache in your directory (0777 on unix-linux, if you are not sure that you can do what you do not want and do not know what windows are)

and then, as was said, gives a good path to opening, and not just to the file name

-1
source

Source: https://habr.com/ru/post/946572/


All Articles