How to run system commands using php?
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY jijimol.john
3 years ago
Commands
0
comments comment

We can execute system commands using SHELL. shell_exec is a PHP function that returns the output as a string or null if it is a wrong output. Note that, this function is disabled when the PHP is running in a safe mode.

I had a requirement to remove all files from one of my folder using PHP. Here I am sharing a small snippet for removing all files in a folder via shell_exec.


<?php
 $deletefiles = 'rm -rf {folder name}/*';
 shell_exec($deletefiles);
 ?>

You can execute any system commands using shell_exec like the above example. Need any help, contact us.


RELATED ARTICLE

more_horiz
close

on 20th March 2015 / by fazeela.ma
Git is a control system for developing softwares. There are a number of git commands (Git reference). While searching bringing a commit from one branch to another, I came across an interesting topic called cherry picking. Cherry pick a commit? Sounds interesting!!! Git Commands Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 12th August 2015 / by jijimol.john
rsync command is used to synchronize files and folder from source to destination. It may be same or different server. If the synchronization is in between different servers we have to use ssh credentials for connecting the two. Remote Sync Commands Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

on 21st August 2015 / by jijimol.john
We can execute system commands using SHELL. shell_exec is a PHP function that returns the output as a string or null if it is a wrong output. Note that, this function is disabled when the PHP is running in a safe mode. Commands Leave a reply Your email address will not be published. Required fields are marker *
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.