php - fopen() not creating a file nor writing to it (if i create the file manually)

first if all im sorry if i posted this in the wrong place but i really dont know where to ask this and especially that im not sure if the problem is of the code or something in my system
so i have a php7.3 server with apache2 running on kali linux 2019.4 and i wanted to make a simple fopen php app to write data entered from the user to the server so i enabled allow_url_fopen in the php.ini for both apache2 folder and the cli folder
this is my code
<html>
<style>
body{
background-color: black;
color: white;
}
.lli{
width: 80%;
}
</style>
<center>
<font color="white">
<br>
<br>
<form method="POST" href="VideoYeeter.php">
<br>
<input type="text" name="url" placeholder="Enter YouTube Video URL here">
<br><br>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (isset($submitted)) {
$file = fopen("/srv/htdocs/vid.ytdl" ,"w+") or die ("can't open file"); //this is my web folder (/srv/htdocs)
fopen($file,$_POST['url']);
fclose($file);
} else { ?>
<form method="POST" action="VideoYeeter.php">
<input type="submit" name="submitted" value="Download"></form>
<?php } // end of form ?><br><br>
<div><iframe src="vlog.php"></div>
</center>
</html>
the code runs as if there is no problem but when i go to see if the file was created i dont find anything
i tried chmod-ing everything to 777 and chown-ing everything to root i tried to output the file to another place accessible on the server (not /root/)
and yet it doesnt work also if i create the file myself nothing gets written to it
so could i get some help please
Answer
Solution:
turns out im just as dumb as a spoon im checking for an undefined variable which made the if statment false so to fix it i just did
if(isset($_POST['submitted'])){//code}
instead of
if(isset($submitted)){//code}
Answer
Solution:
In addition to Alvaro's answer $submitted might be the issue so what might be worth a try is to just do a simple test that does not rely on a variable being set to write to the file.
If it writes to the file then that proves the variable is the issue. Failing that check your web server error logs to see what's happening there.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.