• Resolved ashton1993

    (@ashton1993)


    Heya, my website is here, I’m trying to make it so that when a user registers on my site it’ll automatically create a directory for them (http://pixelsgame.org/upload/USERNAME) which they can later use for uploading files to use in their posts, I’m using this code just after the account activation:

    ‘<?php mkdir(“/upload/” . $user_info->user_login); ?>’

    But the directory is not created upon activation and I receive this error:

    ‘Warning: mkdir() [function.mkdir]: Permission denied in /hermes/bosweb/web096/b966/ipg.pixelsgamenet/wp-content/plugins/buddypress/bp-themes/bp-default/registration/activate.php on line 14’

    I made sure that activate.php has permisions 0777 (everything turned on) but still get the same error, don’t suppose anybody could help, also I know it’s terribly thankless of me to ask but I’d be eternally grateful if you could also look at this other unresolved issue I’m trying to tackle. Thanks a lot for looking!

Viewing 9 replies - 1 through 9 (of 9 total)
  • What’s on Line 14 of activate.php?

    Thread Starter ashton1993

    (@ashton1993)

    Oh sorry, it’s:

    <?php mkdir("/upload/" . $user_info->user_login); ?>

    Should have specified that was line 14

    Ah sorry, should have guessed myself.

    Would it be a case of that /upload/ is the absolute path rather than the relative path?

    And you’re trying to create a folder outside your designated area on a shared server?

    Could you look at something like wp_upload_dir()?

    http://codex.wordpress.org/Function_Reference/wp_upload_dir

    Thread Starter ashton1993

    (@ashton1993)

    Heh, it was only when you posted that I realized I could change the upload directory rather than set up another FTP account to get decent looking links. Anyways I changed the code to:

    <?php $upload_dir = wp_upload_dir(); ?>
    <?php mkdir($upload_dir . "" . $user_info->user_login); ?>

    Which doesn’t return an error phew, though neither does it create a directory for that user, I however came to the realization $user_info->user_login should only return a value when a user is logged in so I went on to write:

    24		<?php $upload_dir = wp_upload_dir();
    25		$dirname = $_POST[$user_info->user_login];
    26		$filename = "/$upload_dir/{$dirname}/";
    27
    28		if (file_exists($filename)) {
    29		echo ""; } else {
    30		mkdir($upload_dir . "" . $user_info->user_login);
    31    		}
    32		?>

    Then chuck it in the theme header but got this error

    Warning: mkdir() [function.mkdir]: File exists in /hermes/bosweb/web096/b966/ipg.pixelsgamenet/wp-content/plugins/buddypress/bp-themes/bp-default/header.php on line 30

    Sorry if I’m just being silly.

    Thread Starter ashton1993

    (@ashton1993)

    I’ve refined my code more though still having some dificulity, it should work but for some reason it doesn’t:

    <?php
    		global $current_user;
    		get_currentuserinfo();
    
    		$filename = "http://www.pixelsgame.org/upload/{$current_user->user_login}/";
    
    		if (file_exists($filename)) {
    		echo 'http://www.pixelsgame.org/upload/' . $user_info->user_login . ' supposedly already created'; } else {
    		echo 'http://www.pixelsgame.org/upload/' . $current_user->user_login . ' supposedly just created';
    		mkdir("$filename");
        		}
    		?>

    It echoes “http://www.pixelsgame.org/upload/ashton supposedly just created” when I use it though doesn’t create the directory, any clues?

    Hi,

    You can’t create a dir via a URL. Mkdir operates at a OS level to create the directory.

    From your above errors, your path on your server should be something like

    /hermes/bosweb/web096/b966/ipg.pixelsgamenet/wp-content/upload/

    Thread Starter ashton1993

    (@ashton1993)

    Awesome! It’s working perfectly now! Well thanks for all the help 🙂 do you think it’d be useful for me to post the code somewhere it can be used again by others or would I just be clogging things up?

    I’d be interested in having a look out of curiosity, so if you pastebin the code, and link it here, at least if someone is ever searching for the same solution they have a starting point.

    Thanks,
    Harry

    Thread Starter ashton1993

    (@ashton1993)

    Sorry, just ended up a bit busy and forgot about this but basically I was using inline upload and had modified it so that when a user uploaded a file it would go to their own directory (I’m using buddypress for a social networking rig) except I discovered the plugin WP-Filebase which makes this obsolete >_<

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Making directories for users?’ is closed to new replies.