Jump to content

form input and shell commands


dangtran09

Recommended Posts

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

Link to comment
Share on other sites

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} " ) ;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.