Answers for "php exec"

PHP
4

php run command line

shell_exec('ls');
// or
exec('ls');
Posted by: Guest on June-23-2020
0

how to execute cmd command in php

I'm not sure what shell you are going to get with this function, but you can find out like this:

<?php
$cmd = 'set';
echo "<pre>".shell_exec($cmd)."</pre>";
?>

On my FreeBSD 6.1 box I get this:

USER=root
LD_LIBRARY_PATH=/usr/local/lib/apache2:
HOME=/root
PS1='$ '
OPTIND=1
PS2='> '
LOGNAME=root
PPID=88057
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
SHELL=/bin/sh
IFS='     
'

Very interesting.  Note that the PATH may not be as complete as you need.  I wanted to run Ghostscript via ImageMagik's "convert" and ended up having to add my path before running the command:

<?php
$cmd = 'export PATH="/usr/local/bin/"; convert -scale 25%x25% file1.pdf[0] file2.png 2>&1';
echo "<pre>".shell_exec($cmd)."</pre>";
?>

ALSO, note that shell_exec() does not grab STDERR, so use "2>&1" to redirect it to STDOUT and catch it.
Posted by: Guest on November-06-2020
1

exec output php

$output = exec('ls');
Posted by: Guest on June-25-2020
0

php exec

<?php
$connect = ftp_connect('111.111.111');  //connect to server

$login = ftp_login($connect, 'ftp_username', 'ftp_password'); 

if($login) 
{ 
    if(ftp_put($connect, '/home/user/john/tes.txt','tes.txt', FTP_BINARY)) 
    { 
        echo "Success";
    } 
} 

ftp_close($connect); 
?>
Posted by: Guest on January-05-2021
-1

php exe file

teee
Posted by: Guest on September-05-2020

Browse Popular Code Answers by Language