Jump to content

Recommended Posts

The code now sits at:

<?php
$link = mysql_connect('localhost', 'testusr', 'testpw');
mysql_select_db('testdb', $link);
$query = "select fordir from products where id=".$_POST['id'].""; $result = mysql_query($query); $fordir = mysql_fetch_array($result);
$query = "select category from products where id=".$_POST['id'].""; $result = mysql_query($query); $category = mysql_fetch_array($result);
$query = "DELETE from `products` where `id` = ".$_POST['id']."";
$cmd = "cp -rf /var/www/http/test.com/products/{$fordir['fordir']}/{$category['category']}/{$_POST['id']} /home/n/Documents/test.com\\ codebase";
echo "command is: $cmd <BR>";
$retval = shell_exec($cmd);
echo $retval;
echo "result: $retval";
mysql_query ($query);
mysql_close($link);
?>

 

The code echo's fine:

command is: cp -rf /var/www/http/test.com/products/men/belts/69 /home/n/Documents/test.com\ codebase

result:

 

... and works when I paste it into my Linux shell, but its not working in PHP. Not even a mention of it in error.log.

I am now using:

system ("mkdir /1");
system ("mkdir /home/n/1");
system ("mkdir /var/www/http/test.com/1");

 

FAIL

FAIL

SUCCESS

 

I smell write permission problems. But fuckin PHP didn't say this in error.log!!!!!!!! I will continue to test and let you guys know....

I think I am a noob. I forget PHP will running as www-data and not root!!!! OMG

Which is what disturbs me the most, as there is clearly an error... or even a paradox!

 

Well it depends on how you look at it.  To php the function call is the shell_exec.  It is completing.  If the cp command executes but doesn't execute in the way you want, to php it is still executing. 

 

There are also a number of php.ini settings that can stop operating system commands from running, as well as operating system permissions, and environment issues that can effect a script running.  I don't think that is the source of your problem but you should read about them and check against your configuration just to be sure:  http://us3.php.net/manual/en/ini.sect.safe-mode.php

 

The way php is being used is another issue.  How these external calls work or not is highly dependent on the operating system, the webserver and the way it's been configured.  There's just way too much involved for me to summarize. 

 

Since these commands seem to work for you from the shell an quick way around your problem might be to make a bash script that takes parameters, unit test that and call the bash script in your shell_exec.  You can in your script redirect std output and stderr to a file.  In fact you might experiment with that just with the current command you are running.  I did note that you are using spaces in directory names -- not a great idea, since they add more things that could go wrong as Thorpe pointed out.  For example, one of your paths -- I can't remember which one, has a space in it.

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.