Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2012, 07:34 PM   PM User | #1
Remix919
Regular Coder

 
Join Date: Jan 2006
Posts: 193
Thanks: 29
Thanked 0 Times in 0 Posts
Remix919 is an unknown quantity at this point
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    
            
        
}

Remix919 is offline   Reply With Quote
Old 01-08-2012, 07:45 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
$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/
felgall is offline   Reply With Quote
Old 01-08-2012, 08:31 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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;
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Old 01-08-2012, 09:00 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Users who have thanked Spookster for this post:
tangoforce (01-08-2012)
Old 01-08-2012, 09:38 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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!
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is online now   Reply With Quote
Old 01-09-2012, 12:24 AM   PM User | #6
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Where do you call your function from? You do see that it is a private function?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-09-2012, 03:03 PM   PM User | #7
Remix919
Regular Coder

 
Join Date: Jan 2006
Posts: 193
Thanks: 29
Thanked 0 Times in 0 Posts
Remix919 is an unknown quantity at this point
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.
Remix919 is offline   Reply With Quote
Old 01-09-2012, 04:23 PM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Remix919 (01-09-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:34 PM.


Advertisement
Log in to turn off these ads.