Umer
Umer

Reputation: 203

Saving file to a different directory in php

I have 2 directories in "Members" directory

Members
     Admin
     Users

in the Admin directory there is a php script that is receiving Http POST request and saving the contents into a file , but the file name is the first value of POST request.

How can I save the contents to User directory instead of Admin directory

This is my attempt but it gives error :

<?php
$entityBody = file_get_contents('php://input');
$filn = $_POST["account"];
$size =  count($_POST);
file_put_contents('./Users/'.$filn , file_get_contents('php://input')); 
?>

Error:

Parse error: syntax error, unexpected variable "$filn" in C:\xampp\htdocs\auth\Admin\add.php on line 6

Upvotes: 0

Views: 362

Answers (1)

Partharaj Deb
Partharaj Deb

Reputation: 904

Try as follows-

file_put_contents(__DIR__."/../Users/$filn", $entityBody); 

Upvotes: 1

Related Questions