I'm trying to creat and store a file locally in my pc using any web programing language

32
March 15, 2019, at 9:40 PM

I'm trying to save a txt file in my pc locally with php, but not in the download folder. I need to add in different folder.

Here is my code

$txt = "$dirname/Contact.txt"; 
$fh = fopen($txt, 'w+');
exit();
fwrite($fh,$txt);
close($fh); 
Answer 1

You can use $_SERVER variable to specify your path

$myTxt = $_SERVER['DOCUMENT_ROOT'] . "you/path/directory"

But remember that the path first is in your project, you may go out with "../"

And your exit(); command, this kills your code. Put this at the end of the file. It will never reaches close($fh);

Maybe only fixing this exit(); will solve your problem.

READ ALSO
Grabbing userID and field upon user creation

Grabbing userID and field upon user creation

I currently have a function that simply creates a user record in the database

21
Submitting 2 Forms with 1 Button or 1 Input

Submitting 2 Forms with 1 Button or 1 Input

currently i have 2 Buttons (well 1 Button and 1 Input with a Bootstrap button class) I use to upload a picture, and add a text to that picutre

20
How to optimize a mysql query

How to optimize a mysql query

I have a problem with a mysql query that sometimes needs more than 80 secs to execute

53