how to change teh folder name in which i am uploading the images?

i am not uploading my images to the specific folder. i am uploading it in the folder named $title.
now i have 2 tables.
one is album with fields id,title,desc
another is photo_gallery with fields id,image,album_name

the title of one is same as the album_name of another. it is basically the album into which i am uploading the images. now the question is if i edit the first table means album title then the folder name should also change and in another table album_name should also change.
how can i do this?
designersxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

designersxAuthor Commented:
i had taken the hidden field and changed the name of album_name in another table.
now only task that is left is how i should change the folder name. i explain you with example.

For example, you have given the album name that is abc and uploaded the 5 images in that. ok, now you change the name of the album and now that is xyz and those images should be in xyz folder and not in abc folder.

i need an idea for this.
0
designersxAuthor Commented:
i want to change the folder name because i need to display the images also.
0
nbruno02Commented:
If I understand your problem correctly, it sounds like you're going to have to:

1. Create the new folder
2. Read all of the files from the old folder and copy it into the new folder
3. Delete the old folder

Something like the following functions should help you. The function you should call is rename_folder(). Make sure the arguments you pass to that function are directories, so, for your example, you would pass $old_folder as /home/user/public_html/albums/abc/ and $new_folder as /home/user/public_html/albums/xyz

// Taken from PHP.net/rmdir comments
function delete_directory( $dir) 
{
	$files = glob( $dir . '*', GLOB_MARK );
	foreach( $files as $file )
	{
		if( substr( $file, -1 ) == '/' )
			delete_directory( $file );
		else
			unlink( $file );
	}
    rmdir( $dir);
}
 
// Taken from PHP.net/copy comments
function smartCopy($source, $dest, $options=array('folderPermission'=>0755,'filePermission'=>0755))
    {
        $result=false;
       
        if (is_file($source)) {
            if ($dest[strlen($dest)-1]=='/') {
                if (!file_exists($dest)) {
                    cmfcDirectory::makeAll($dest,$options['folderPermission'],true);
                }
                $__dest=$dest."/".basename($source);
            } else {
                $__dest=$dest;
            }
            $result=copy($source, $__dest);
            chmod($__dest,$options['filePermission']);
           
        } elseif(is_dir($source)) {
            if ($dest[strlen($dest)-1]=='/') {
                if ($source[strlen($source)-1]=='/') {
                    //Copy only contents
                } else {
                    //Change parent itself and its contents
                    $dest=$dest.basename($source);
                    @mkdir($dest);
                    chmod($dest,$options['filePermission']);
                }
            } else {
                if ($source[strlen($source)-1]=='/') {
                    //Copy parent directory with new name and all its content
                    @mkdir($dest,$options['folderPermission']);
                    chmod($dest,$options['filePermission']);
                } else {
                    //Copy parent directory with new name and all its content
                    @mkdir($dest,$options['folderPermission']);
                    chmod($dest,$options['filePermission']);
                }
            }
 
            $dirHandle=opendir($source);
            while($file=readdir($dirHandle))
            {
                if($file!="." && $file!="..")
                {
                     if(!is_dir($source."/".$file)) {
                        $__dest=$dest."/".$file;
                    } else {
                        $__dest=$dest."/".$file;
                    }
                    //echo "$source/$file ||| $__dest<br />";
                    $result=smartCopy($source."/".$file, $__dest, $options);
                }
            }
            closedir($dirHandle);
           
        } else {
            $result=false;
        }
        return $result;
    }
 
// Make sure you specify these as directories
function rename_folder( $old_folder, $new_folder)
{
	// Create the new folder if it doesn't already exist
	if( !is_dir( $new_folder))
	{
		@ mkdir( $new_folder);
	}
 
	// Copy the contents from the old folder to the new folder
	smartCopy( $old_folder, $new_folder);
 
	// Delete the old folder
	rmdir( $old_folder);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.