andytan91 Posted July 21, 2010 Share Posted July 21, 2010 Hey guys, how do i pass the $_POST['argument'] into the $newfile variable successfully? <?php $file = 'service_pack.bat'; $newfile = 'C:\xampp\htdocs\new\old\$_POST['argument']'; if(isset($_POST['argument']) && $_POST['submit'] == "Update") { copy($file, $newfile); } ?> <b>Save Template</b> <p> <form action="copyfile.php" method="post"> Save file as: <input type="text" name="argument"<br> <input type="submit" name="submit" value="Update"> <p> </form> </p> Quote Link to comment https://forums.phpfreaks.com/topic/208388-read-_post-value-in-a-variable/ Share on other sites More sharing options...
GKWelding Posted July 21, 2010 Share Posted July 21, 2010 $newfile = 'C:\xampp\htdocs\new\old\'.$_POST['argument']; OR $newfile = "C:\xampp\htdocs\new\old\$_POST['argument']"; notice the use of single and double quotes, basic php. Quote Link to comment https://forums.phpfreaks.com/topic/208388-read-_post-value-in-a-variable/#findComment-1088972 Share on other sites More sharing options...
andytan91 Posted July 21, 2010 Author Share Posted July 21, 2010 I tried both and it doesnt work..the 2nd one says... Warning: copy(C: mpp\htdocs ew\old$_POST['argument']) [function.copy]: failed to open stream: Invalid argument in C:\xampp\htdocs\new\copyfile.php on line 10 Save Template Quote Link to comment https://forums.phpfreaks.com/topic/208388-read-_post-value-in-a-variable/#findComment-1088984 Share on other sites More sharing options...
bh Posted July 21, 2010 Share Posted July 21, 2010 2nd: you need those brackets $newfile = "C:\xampp\htdocs\new\old\{$_POST['argument']}"; (Anyway this way of creating your newfile is not the best practice.) Quote Link to comment https://forums.phpfreaks.com/topic/208388-read-_post-value-in-a-variable/#findComment-1088986 Share on other sites More sharing options...
andytan91 Posted July 21, 2010 Author Share Posted July 21, 2010 it gives me Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\new\copyfile.php on line 3... what other options do i have? Quote Link to comment https://forums.phpfreaks.com/topic/208388-read-_post-value-in-a-variable/#findComment-1088988 Share on other sites More sharing options...
bh Posted July 21, 2010 Share Posted July 21, 2010 Oh, sure... cuz the '\' -> you have to escape it 1st: $newfile = "C:/xampp/htdocs/newold/{$_POST['argument']}"; 2nd: $newfile = "C:\\xampp\\htdocs\\newold\\{$_POST['argument']}"; a better way that you create a simple filename from your $_POST['argument'] Quote Link to comment https://forums.phpfreaks.com/topic/208388-read-_post-value-in-a-variable/#findComment-1088990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.