tags:

views:

28

answers:

2

I have a script running on a staging site where it takes an uploaded image, creates a directory (if it exists) and uploads the image to said directory.

I am trying to change the directory that gets created to the live site and having no luck. Pretty certain that it's this block of code that is still looking for the staging URL instead of the live.

function chmodDirectory( $path = '.', $level = 0 ){  
$ignore = array( 'cgi-bin', '.', '..' ); 

$dh = @opendir( $path ); 


while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory 
  if( !in_array( $file, $ignore ) ){
    if( is_dir( "$path/$file" ) ){
      chmod("$path/$file",0777);
      chmodDirectory( "$path/$file", ($level+1));
    } else {
      chmod("$path/$file",0777); // desired permission settings
    }//elseif 

  }//if in array 

}//while 

closedir( $dh ); 

}//function

?> Thanks in advance for any help!

EDIT: The problem lies in that even though I've changed the paths and the database stores the correct URLs, the directory that i wish to be created or accessed is still being created / accessed on the staging directory.

A: 

The file-related commands in PHP are all "current working directory" aware. You start your chmodDirectory() with . as the path, which means "the current working directory", which is by default the directory the script exists in.

If you're running the staging site as a sub-directory of the "live" site, there's no way to have the function as-is point at the live directories, as you're going off the relative '.' directory and only dig deeper. For example, if your script is in:

/home/sites/example.com/htdocs/staging/v1.1/upload.php

then the first directory processed will be

/home/sites/example.com/htdocs/staging/v1.1/

If you want to start the process in the "live" area, you'd have to call the function with an originating path of:

chmodDirectory('../..'); // start two directories above the current working dir

or better yet:

chmodDirectory('/home/sites/example.com/htdocs/'); // start at this absolute path

as the path instead, so it'll be working off the "live" version instead of starting within the staging area.

Marc B
A: 

Hey Guys, thanks for your help... the error is actually occuring from the open_basedir in the php.ini settings. I am unable to write a directory because i am under a subdomain directory.

Matt Nathanson