Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

mkdir and rmdir with php

  • 26-03-2011 11:50pm
    #1
    Closed Accounts Posts: 5,824 ✭✭✭


    quick question regarding mkdir and php.

    can i use mkdir to create a folder say here

    htdocs/project/useraccounts/

    and the foldername in there assigned by a variable name?

    so when a user registers, a folder is made for their username in the useraccounts folder.

    $foldername = $_POST;

    the above works fine and the folder is created.
    but its in the project folder.

    $foldername = "/useraccounts/".$_POST;

    trying something like this, but no joy yet.

    any suggestions?

    also trying to remove the directory when the user terminates their account, but ive read that using rmdir wont work if there are files in the folder.

    would deltree be a good idea?


Comments

  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    $foldername = $_POST["username"];
    mkdir("useraccounts/" . $foldername, 0777);

    got it.... :)


    now, trying to move the file from the tmp folder...

    $id = $_SESSION;

    else
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "useraccounts/" . $_id . $_FILES["file"]["name"]);

    }

    using this just moves the file from the tmp to the useraccounts folder.

    how would i get it to move to the user's folder?


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    move_uploaded_file($_FILES["file"]["tmp_name"],
    "useraccounts/" . $_id . "/".$_FILES["file"]["name"]);


  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    sadly thats still putting the image into the useraccounts folder and not useraccounts/specifieduser/


  • Registered Users, Registered Users 2 Posts: 101 ✭✭jreanor


    I found this very nice function to delete a folder and all its contents. It could be useful:
    [PHP]function rrmdir($path)
    {
    return is_file($path)?
    @unlink($path):
    array_map('rrmdir',glob($path.'/*'))==@rmdir($path)
    ;
    }[/PHP]
    It's not my code, I found it in the comments here: http://php.net/manual/en/function.unlink.php

    James


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    sadly thats still putting the image into the useraccounts folder and not useraccounts/specifieduser/

    Really ? If so, then $id isn't being set correctly.


  • Advertisement
  • Closed Accounts Posts: 5,824 ✭✭✭RoyalMarine


    god damn it...

    dont know why i didnt cop that i changed variable name to user from username...

    cheers liam! working nicely now!


Advertisement