Author Topic: quick php question  (Read 1673 times)

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
quick php question
« on: 18 January 2003, 12:04 »
How can I create a directory using php without useing the system() function? (the host disabled system()) Sorry to be so short, but i'm going to go see if I can find it (again), thanks.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
quick php question
« Reply #1 on: 18 January 2003, 12:59 »
mkdir("/some/dir",755);

Or if you have ftp access you might be able to create the directory through FTP and chmod it depending on if your host allows it.

[ January 18, 2003: Message edited by: void main ]

Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
quick php question
« Reply #2 on: 18 January 2003, 13:01 »
quote:
Originally posted by void main:
mkdir("/some/dir","755");

Or if you have ftp access you might be able to create the directory through FTP and chmod it depending on if your host allows it.



i cant use ftp or anything like that... i am making an automated page for adding users to the .htpasswd file of my site, and then giving them an upload directory. ftp would be difficult to automate, but i'll try that mkdir() though.

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
quick php question
« Reply #3 on: 18 January 2003, 13:03 »
Oh, thought it was a one time thing. Yeah, I made a mistake in the mkdir() syntax. You need 4 octal mode chars. For instance to make a directory with full access for everyone (rwxrwxrwx) you would:

mkdir("/some/dir",0777);

[ January 18, 2003: Message edited by: void main ]

Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
quick php question
« Reply #4 on: 18 January 2003, 13:07 »
it made the dir, i chosoe permissions 777 (i have reasons dont worry), but the permissions are all set to nothing except for the owner, which is apache. i can't chmod from the shell, because it's not mine. any ideas why the permissions didn't set right and how to fix it? (i'm not just asking, i've been looking)

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
quick php question
« Reply #5 on: 18 January 2003, 13:10 »
You can use:

chmod("/some/dir",0777);

Read my previous post about my error in the mkdir() command.

Also go to www.php.net, they have the ultimate function list.
Someone please remove this account. Thanks...

Stryker

  • VIP
  • Member
  • ***
  • Posts: 1,258
  • Kudos: 41
quick php question
« Reply #6 on: 18 January 2003, 13:12 »
thanks, fixed that. (sorry i'm a bit new to php), but can I go through a file, specifically a .htpasswd file, and delete a line containing a specific text (the username) using php?

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
quick php question
« Reply #7 on: 18 January 2003, 20:57 »
Yes. If the userid is on a line by itself you could read the .htpasswd file and write it to a new file, skipping the line containing the id. If there are other userids on the same line you can use the ereg_replace() function on the line in question something like:

...
$line = ereg_replace("joeblow","",$line);
...

Look on www.php.net for the functions fopen(), ereg_replace(), fread(), fgets(), fclose(). You might want to search google for examples of reading and writing files in PHP.

[ January 18, 2003: Message edited by: void main ]

Someone please remove this account. Thanks...