Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Creating a directory

    Hey, im new to php and I want to know how to create a directory. I tried with the code below but it just shows the error message:

    Warning: mkdir() [function.mkdir]: No such file or directory in C:\xampp\htdocs\planetgay\upload.php on line 5
    Could not make directory

    Couple someone please point me in the right direction. My code is below.

    PHP Code:
    <?php


    // create directory
    mkdir("tmp/stuff") or die ("Could not make directory");

    ?>
    Thanks in advance
    Danny

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Have you checked you have write access to the parent directory?
    You can not say you know how to do something, until you can teach it to someone else.

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i am running this on xampp. So the parent directory is the one the file is stored in?

  • #4
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    tmp it seems like.
    You can not say you know how to do something, until you can teach it to someone else.

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    on Linux (which it seems like your using judging by the error message), mkdir produces the error message No such file or directory when the parent folder doesn't exist.

    try
    PHP Code:
    mkdir("tmp/") or die ("Could not make directory");
    mkdir("tmp/stuff") or die ("Could not make directory"); 

  • Users who have thanked psykx for this post:

    Hayes (11-25-2007)

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by psykx View Post
    on Linux (which it seems like your using judging by the error message)
    "No such file or directory in C:\xampp\htdocs\planetgay\upload.php"
    That looks like a Linux path to you?

    Quote Originally Posted by psykx View Post
    mkdir produces the error message No such file or directory when the parent folder doesn't exist.
    You get that error on ANY operating system when the parent directory doesn't exist.

  • #7
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks psykx it fixed that problem. Next thing i need help on i want it to make a folder depending on what is in the database 'id'.

    I tried this but it didnt work.
    PHP Code:
    mkdir("images/["id"]") or die ("Could not make directory"); 
    Thanks

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Show the rest of your code. Where you select the ids and such.

  • #9
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Changed how i am doing it a bit now. Im going to create a folder with users username. My code so far is:

    PHP Code:
    <?php
    require_once('includes/Sentry.php');
    $theSentry = new Sentry();
    if (!
    $theSentry->checkLogin(2) ){ header("Location: cmsAdmin/login.php"); die(); }
    ?>
    <?php

    // Require the classes
    require_once('includes/DbConnector.php');

    // Create an object (instance) of the DbConnector and Validator
    $connector = new DbConnector();

    $getUser $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."');

    // create directory
    mkdir("
    images/('user')") or die ("Could not make directory"); 
    ?>
    I am getting all the session information from sentry.php

    PHP Code:
    <?php
    ////////////////////////////////////////////////////////////////////////////////////////
    // Class: sentry
    // Purpose: Control access to pages
    ///////////////////////////////////////////////////////////////////////////////////////
    class sentry {
        
        var 
    $loggedin false;    //    Boolean to store whether the user is logged in
        
    var $userdata;            //  Array to contain user's data
        
        
    function sentry(){
            
    session_start();
            
    header("Cache-control: private"); 
        }
        
        
    //======================================================================================
        // Log out, destroy session
        
    function logout(){
            unset(
    $this->userdata);
            
    session_destroy();
            return 
    true;
        }

        
    //======================================================================================
        // Log in, and either redirect to goodRedirect or badRedirect depending on success
        
    function checkLogin($user '',$pass '',$group 10,$goodRedirect '',$badRedirect ''){

            
    // Include database and validation classes, and create objects
            
    require_once('DbConnector.php');
            require_once(
    'Validator.php');
            
    $validate = new Validator();
            
    $loginConnector = new DbConnector();
            
            
    // If user is already logged in then check credentials
            
    if ($_SESSION['user'] && $_SESSION['pass']){

                
    // Validate session data
                
    if (!$validate->validateTextOnly($_SESSION['user'])){return false;}
                if (!
    $validate->validateTextOnly($_SESSION['pass'])){return false;}

                
    $getUser $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."' AND thegroup <= ".$group.' AND enabled = 1');

                if (
    $loginConnector->getNumRows($getUser) > 0){
                    
    // Existing user ok, continue
                    
    if ($goodRedirect != '') { 
                        
    header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
                    }            
                    return 
    true;
                }else{
                    
    // Existing user not ok, logout
                    
    $this->logout();
                    return 
    false;
                }
                
            
    // User isn't logged in, check credentials
            
    }else{    
                
    // Validate input
                
    if (!$validate->validateTextOnly($user)){return false;}
                if (!
    $validate->validateTextOnly($pass)){return false;}

                
    // Look up user in DB
                
    $getUser $loginConnector->query("SELECT * FROM cmsusers WHERE user = '$user' AND pass = PASSWORD('$pass') AND thegroup <= $group AND enabled = 1");
                
    $this->userdata $loginConnector->fetchArray($getUser);

                if (
    $loginConnector->getNumRows($getUser) > 0){
                    
    // Login OK, store session details
                    // Log in
                    
    $_SESSION["user"] = $user;
                    
    $_SESSION["pass"] = $this->userdata['pass'];
                    
    $_SESSION["thegroup"] = $this->userdata['thegroup'];
                                    
                    if (
    $goodRedirect) { 
                        
    header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
                    }
                    return 
    true;

                }else{
                    
    // Login BAD
                    
    unset($this->userdata);
                    if (
    $badRedirect) { 
                        
    header("Location: ".$badRedirect) ;
                    }        
                    return 
    false;
                }
            }            
        }
    }    
    ?>
    The error message i get is:

    Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\planetgay\upload.php on line 17

    can anyone help?
    Thanks in advance

  • #10
    New Coder
    Join Date
    Nov 2007
    Posts
    72
    Thanks
    0
    Thanked 1 Time in 1 Post
    It seems you're missing a quotation on line 14 at the end of the SQL statement. Look at the code you just posted and the error should be apparent.

  • #11
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i cant see the error. Please help

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    $getUser $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."'");

    // create directory
    mkdir("images/{$user}") or die ("Could not make directory"); 
    Change $user to the variable you select from the database.

  • #13
    New Coder
    Join Date
    Nov 2007
    Posts
    42
    Thanks
    3
    Thanked 0 Times in 0 Posts
    That seems to of fixed one problem the next one i have is i am getting this error message:
    Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\planetgay\upload.php on line 14

    The code is now like this:

    PHP Code:
    <?php
    require_once('includes/Sentry.php');
    $theSentry = new Sentry();
    if (!
    $theSentry->checkLogin(2) ){ header("Location: cmsAdmin/login.php"); die(); }
    ?>
    <?php

    // Require the classes
    require_once('includes/DbConnector.php');

    // Create an object (instance) of the DbConnector and Validator
    $connector = new DbConnector();

    $getUser $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."'");

    // create directory
    mkdir("images/{$getUser}") or die ("Could not make directory");  
    ?>
    Thanks for all the help

  • #14
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    try reading over your code, you're making a lot of sloppy mistakes. Take a look at what you call your variables, and then what you use when you re-use them- check they're the same.

    PHP error messages might at a first glance look unintelligible, but they're really quite specific. The first thing to look for is the line number, in this case 14. Which line of the code you've posted is 14? It's really helpful for people looking at your code to know this. The rest of the error tells you what the problem is- you're trying to call the query() method on something that isn't an object- why would that be? is $loginConnector somehow not an object when you think it should be? *shift eyes up and left* oh. now you feel silly?
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #15
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    At least try to figure things out yourself. Don't just post the new issue. This is a very simple problem to debug.

    PHP Code:
    $connector = new DbConnector();

    $getUser $loginConnector-> 
    $connector vs. $loginConnector?


  •  

    Posting Permissions

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