Results 1 to 6 of 6

Thread: Variables in directories

  1. #1
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Variables in directories

    My problem is that I need a directory to be created on my ftp account (File Manager), which has the title of a variable. In other words, this is on a registration page, and I would like the directory created to be the name of the username submitted.

    Here's what I have so far:

    PHP Code:
    @ftp_mkdir($conn_id'/public_html/profiles/" . $userUsername . "'); 
    Is this possible to do? If so, how could it be done?

    Thanks in advance for any help, Andy.

  2. #2
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    Try this:
    PHP Code:
    $new_dir '/public_html/profiles/' $userUsername;

    @
    ftp_mkdir($conn_id$new_dir); 
    Suggestion: I know the user-submitted examples in the php manual make use of the @ prefix to functions. But, generally, I don't believe that to be the best approach.

    @ suppresses errors. It's far better in my opinion to handle the errors in your code rather than suppressing them.

  3. The Following User Says Thank You to BabblingIdjit For This Useful Post:

    AndyA (11-27-2008)

  4. #3
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    if its on the same website couldn't you jsut use mkdir?

  5. #4
    Join Date
    Nov 2008
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Wow. Fantastic!

    Thanks sooo much John. It's all working great now!

    Couldn't have done it without you, great idea! Thanks a million.

    Here's my final code for that section:

    PHP Code:
        $ftp_server $ftpserver;
        
    $ftp_user $ftpuser;
        
    $ftp_password $ftppass;

        
    $conn_id ftp_connect($ftp_server);
        
    $login_result ftp_login($conn_id$ftp_user$ftp_password);

        if((!
    $conn_id) || (!$login_result))
        {
                echo 
    "FTP connection has failed!";
                echo 
    "Attempted to connect to $ftp_server for user $ftp_user";
           }

        
    $new_dir '/public_html/profiles/' $userUsername;
        
    ftp_mkdir($conn_id$new_dir);

        
    $temp tmpfile();
        
    //Upload the temporary file to server
        
    $new_file '/public_html/profiles/' $userUsername '/' $userUsername;
        
    ftp_fput($conn_id$new_file$tempFTP_BINARY);

        
    ftp_close($conn_id); 

  6. #5
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 9 Times in 9 Posts

    Default

    Cool. you're welcome

  7. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    ftp_mkdir($conn_id, "/public_html/profiles/$userUsername");
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •