dangtran09 Posted August 23, 2015 Share Posted August 23, 2015 hi all - i'm new to php and also new to this forum.i have a form that reads in 2 inputs from the user: database name and directory.<form action="welcome.php" method="post">DB Name: <input type="text" name="dbname"><br>Directory: <input type="text" name="dir"><br><input type="submit"></form>what i'm trying to do is, based on the user inputs, would for the dbname, execute a mysqldump to backup the database. and for directory, execute a tar -czvf $dir.tar.gz $dir.i have the following for the tar part:$directory=$_POST["dir"];$output = shell_exec('tar -czvf {$directory} <?php echo $directory; ?>');however, it's not executing. please help. thanks Quote Link to comment Share on other sites More sharing options...
nik_jain Posted August 24, 2015 Share Posted August 24, 2015 two things. - Variables don't work inside single quoted strings - Since we are alreeady inside <?php tags the <?php echo $directory; ?> part doesn't require <?php and ?> . Also since we just want to join (concatenate) text , the echo is also not required. So Change $output = shell_exec('tar -czvf {$directory} <?php echo $directory; ?>'); to $output = shell_exec("tar -czvf {$directory}.tar.gz {$directory} " ) ; Quote Link to comment 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.