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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    199
    Thanks
    30
    Thanked 0 Times in 0 Posts

    Why won't mkdir() work inside of a function?

    I'm trying to create a directory using mkdir() but it seems to work fine outside the function, but when I put the code inside the function it won't work. Here is the code I'm using:

    PHP Code:
    class Scrapper extends xhttp{

            private function 
    dl_images($images){
                
                
    $getyear date("Y");
                
    $getmonth date("m");
                
    $getday date("d");
                
                
    $pickey 1;
                foreach(
    $images AS $image):
                    
                    
    $post_id $this->db->insert_id;
                    
                    
    $thumb_folder "../classifieds/images/$getyear/$getmonth/$getday/$post_id/";
                    
                    
    mkdir("$thumb_folder"0755);
                    
                    
    $image str_replace("medium","large",$image);
                
                    if(!
    $this->is_image($image)) continue;
                    
                    
    $img file_get_contents($image);
                    
                    
    $image_name endexplode("/"$image ) );
                    
                    
    file_put_contents$thumb_folder $image_name $img );
                    
                    
    $pickey++; 
                    
                endforeach; 
    // END OF LOOPING THROUGH IMAGES    
                
            
    }


  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    9,249
    Thanks
    4
    Thanked 932 Times in 919 Posts
    $thumb_folder doesn't have a value assigned to it inside the function. It is NOT the same $thumb_folder as exists outside the function.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  3. #3
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,048
    Thanks
    106
    Thanked 591 Times in 578 Posts
    Quote Originally Posted by Remix919 View Post
    PHP Code:
            private function dl_images($images){
                    
    $thumb_folder "../classifieds/images/$getyear/$getmonth/$getday/$post_id/";
                    
                    
    mkdir("$thumb_folder"0755); 
    Quote Originally Posted by felgall View Post
    $thumb_folder doesn't have a value assigned to it inside the function. It is NOT the same $thumb_folder as exists outside the function.
    Really? - Could of fooled me!

    @remix:

    Your syntax is wrong. You have a : on the end of your foreach instead of a opening brace { and at the end you need a closing brace } not endforeach;
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.

  4. #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,298
    Thanks
    4
    Thanked 84 Times in 83 Posts
    Quote Originally Posted by tangoforce View Post
    Really? - Could of fooled me!

    @remix:

    Your syntax is wrong. You have a : on the end of your foreach instead of a opening brace { and at the end you need a closing brace } not endforeach;

    Really? - could of fooled me!

    That is valid syntax. Just not commonly used.
    http://php.net/manual/en/control-str...ive-syntax.php
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  5. Users who have thanked Spookster for this post:

    tangoforce (01-08-2012)

  6. #5
    Master Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    5,048
    Thanks
    106
    Thanked 591 Times in 578 Posts
    Quote Originally Posted by Spookster View Post
    Really? - could of fooled me!

    That is valid syntax. Just not commonly used.
    http://php.net/manual/en/control-str...ive-syntax.php
    I stand corrected!
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.

  7. #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where do you call your function from? You do see that it is a private function?

  8. #7
    Regular Coder
    Join Date
    Jan 2006
    Posts
    199
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Yea, I got it working now though, the problem was I wasn't able to create a directory within a non-existent directory, for example if /home exists and I wanted to mkdir /home/test it works, but I couldn't do /home/sub/test unless I made /home/sub first.

  9. #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,026
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    Quote Originally Posted by Remix919 View Post
    Yea, I got it working now though, the problem was I wasn't able to create a directory within a non-existent directory, for example if /home exists and I wanted to mkdir /home/test it works, but I couldn't do /home/sub/test unless I made /home/sub first.
    That's logical. You can override this behaviour if necessary by setting the third parameter of mkdir to true (default is false).

  10. Users who have thanked Fou-Lu for this post:

    Remix919 (01-09-2012)


 

Posting Permissions

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