running linux command under php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scubadiveflorida
Forum Newbie
Posts: 10
Joined: Wed Oct 29, 2003 9:53 am

running linux command under php

Post by scubadiveflorida »

I was wondering what commands you use to run linux commands under php. Like for instance say I wanted to go into the root directory and create a new directory then go to that directory and create a new file there. How would I do that? Thanks.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Take a look to these sections of the PHP Manual:

Execution Operators
Directory functions
Filesystem functions
Program Execution functions

Have a nice day,
Scorphus.
scubadiveflorida
Forum Newbie
Posts: 10
Joined: Wed Oct 29, 2003 9:53 am

What am I doing wrong

Post by scubadiveflorida »

I am trying to create a directory, move into that directory the write a new file and this does not work. What am I doing wrong?


$output = `mkdir test`;
$output .= `cd test`;
$output .= `touch newfile.txt`;
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

$output = `mkdir test`; will attempt to create a directory test inside the current directory.

Does the Apache's user have permission to write to this current directory?

Cheers,
Sco.
User avatar
richie256
Forum Commoner
Posts: 37
Joined: Mon Oct 13, 2003 8:00 pm
Location: Montréal/Canada

Post by richie256 »

Maybe you need to execute these command separately? or add a ";" between each command?

Hope this will help!
Post Reply