0

I get the address of a page and send it to a php page by html form then i want open this file and write some text to it by fopen() function.
My codes :

$open=fopen($subject,"a");  
//$subject is a variable that get the address of page that html for is in.  
// <input type=" text" name="subject" id="f-subject" value=" <?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" />
fwrite($open,"Hello World !");
fclose($open);

now these codes does not work and i get error in explorer.

Warning: fopen(../../Comments/HTML-Learning/chapter1.html): failed to open stream: No such file or directory in ......

any suggestion ??

Arash Younesi
  • 1,671
  • 1
  • 14
  • 23
  • The two codes are exactly equivalent and should behave identically. There's some other factor here you're not showing us. – deceze Oct 13 '16 at 10:28
  • this is true these codes are not all my codes but i tested these codes alonely and the result was same. – Arash Younesi Oct 13 '16 at 10:37
  • Possible duplicate of [PHP - Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Oct 15 '16 at 12:05

1 Answers1

0

You can use relative or absolute path using fopen($path,"flag");

Can verify if the php $subjet handler php file received the data and how you call the handler function in that file or is on another file and in this case are using the include or requiere methods to do that?

So in your code $open=fopen($subject,"a"); the $subject represents a path to a file localization like "ftp", "http", "local path" you are trying to store data on that $subject localization your file localization absolute path must be something like:

$subjet = "/home/rasmus/fichero.txt";
$subjet = "http://www.example.com/";
$subjet = "ftp://user:password@example.com/fichero.txt";

and if you use relative paths for localization your file localization relative path must be something like:

$subjet = "/home/rasmus/../fichero.txt"; //One folder up of your scipt path example
$subjet = "/home/rasmus/../../fichero.txt"; //Two folders up of your script path example

if you are trying to use a http path to store your file you need to use another handler in the destination server http address

Read more at https://www.php.net/manual/es/function.fopen.php

LT-Sites
  • 375
  • 5
  • 15