It is currently Wed 17 Jul, 2019 3:27 am • View unanswered postsView active topics

PHP exec()

PHP exec()

Postby qazxsw21000 » Sun 04 Aug, 2013 10:14 pm

In PHP, there is a function names exec(). This function lets PHP execute non-PHP commands on the server. The following example will tell the server to move "file.ext" in the /var folder to "file2.ext" in the /var/www folder.
Code: Select all
exec('mv /var/file.ext /var/www/file2.ext'); 

But of course PHP has a copy() function too.
Code: Select all

But let's pretend you need Timidity to convert a MIDI file to WAVE for you. We will pretend you already have the MIDI file. The WAVE file will be sent to /var/www/wave.
Code: Select all
exec('timidity "file.mid" -Ow -o "/var/www/wave/file2.wav"'); 

Let's now say you need PHP to empty a temporary directory in your /var/www folder. We will name the temporary folder, "tmp."
Code: Select all
exec('rm /var/www/tmp/*'); 

Do notice these things:
The commands are Linux commands. If you are on a Windows server, use Windows commands.
The public HTML folder is /var/www. Yours might be /home/[site name]/[public_html or www]

This is also why it's a good idea to verify files uploaded to your site.
"Analogies are like sandwiches in that I'm making one now."
Does a set of all sets contain itself?
This statement is false!
Your next task: Refuse this task
User avatar
Posts: 1501
Images: 18
Joined: Sat 06 Aug, 2011 10:37 pm
Location: London, KY

  • Advertisement

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests