Help About Rename.php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help About Rename.php

    how to use rename php in order to rename multiple files from hosting.

    #2
    taken from php dot net:
    PHP Code:
    <?php
     $path = "my_doc";
    
     function getDirectory( $path = '.', $level = 0 ){
    
         $ignore = array( 'cgi-bin', '.', '..' );
    
         $dh = @opendir( $path );
         
         while( false !== ( $file = readdir( $dh ) ) )
         {
             if( !in_array( $file, $ignore ) )
             {
                 $spaces = str_repeat( '&nbsp;', ( $level * 4 ) );
                 if( is_dir( "$path/$file" ) )
                 {
                     echo "<strong>$spaces $file</strong><br />";
                     rename($path."\\".$file, strtolower($path."\\".$file));
                     getDirectory( "$path/$file", ($level+1) );
                     
                 } 
                 else {
                     echo "$spaces $file<br />";
                     rename($path."\\".$file, strtolower($path."\\".$file));
                 }
             }   
         }
         closedir( $dh );
     } 
    
    getDirectory( $path , 0 )
    
    ?>
    it renames all files to lower case ... can be easily modified to (im guessing to include site name)

    Comment


      #3
      thanks but not working........errror on page

      Comment


        #4
        getDirectory( $path , 0 )

        is ment to be:

        getDirectory( $path , 0 );

        Comment


          #5
          Bro it replies as a Warning: readdir(): supplied argument is not a valid Directory resource in /home/..../public_html/....../renamer.php on line 10 what should i do please help. i have to rename all folder in my hostgator hosting in just one click not one by one. please help...............

          Comment


            #6
            save this file as renamer.php or whatever u want
            PHP Code:
            <?php
            ///Posted in Phpadda.in///
            
            // the directory
            // './' - is the current directory
            // '../' - is the parent directory
            // case sensitive
            // e.x.: /home/user or c:\files
            $dir='./';
            
            // 1 - uppercase all files
            // 2 - lowercase all files
            // 3 - do not uppercase or lowercase
            $up=3;
            
            //rename files that have $w in their filename
            //case sensitive
            //set to '' if you want to rename all files
            $w='';
            
            //do not rename files having $n in their filename
            $n='';
            
            //add prefix to files
            $prefix='';
            
            //add postfix
            $postfix='';
            
            //replace
            $replace='Mastiway.com';
            $replace_with='Phpadda.in';
            
            //true - traverse subdirectories
            //false - do not traverse subdirectories
            $tr=true;
            
            
            
            ////// do NOT change anything below this /////////
            set_time_limit(120);
            $files=array();
            error_reporting(E_ERROR | E_PARSE);
            function prep($f,$dir)
            {
                    global $up,$prefix,$postfix,$w,$replace_with,$replace,$n,$files;
                    if(strpos($f,$n)!==false)
                    return $f;
                    $f=str_replace($replace,$replace_with,$f);
                    if($up==1)
                    $f=strtoupper($f);
                    elseif($up==2)
                    $f=strtolower($f);
                    $f=$prefix.$f.$postfix;
                    $files[]=$dir.$f;
                    return $f;
            }
            $i=0;
            function dir_tr($dir)
            {
                    global $i,$w,$tr,$files;
                    $dir=rtrim(trim($dir,'\\'),'/') . '/';
                    $d=@opendir($dir);
                    if(!$d)die('The directory ' .$dir .' does not exists or PHP have no access to it<br><a target="_blank" href="http://phpadda.in">Need help?</a>');
            
            
                    while(false!==($file=@readdir($d)))
                    {
                            if ($file!='.' && $file!='..' && $file!='renamer.php')
                            {
                                    if(is_file($dir.$file))
                                    {
                                            if($w=='' || (strpos($file,$w)!==false))
                                            {
                                                    if(!in_array($dir.$file,$files))
                                                    {
                                                            rename($dir.$file,$dir.(prep($file,$dir)));
                                                            $i++;
                                                    }
                                            }
                                    }
                                    else
                                    {
                                            if(is_dir($dir.$file))
                                            {
                                                    if($tr)
                                                    dir_tr($dir.$file);
                                            }
                                    }
                            }
                    }
                    @closedir($d);
            }
            dir_tr($dir);
            echo '<br>Renamed ' . $i . ' files in directory<br>' . $dir;
            echo "<br>You can now delete renamer.php";
            ?>
            put this file in the folder where u kept ur data example:files folder. now run this script and update database and hit THANKS
            Last edited by Pflash; 18.05.11, 15:07.

            Comment


              #7
              yaar this code was working from many days but now i am facing problem please help me.
              My .htacess is
              RewriteEngine on
              RewriteCond %{HTTP_HOST} ^XXXXXXX.com [NC]
              RewriteRule ^(.*)$ http://www.xxxxxxx.com/$1 [L,R=301]

              ErrorDocument 404 /
              ErrorDocument 403 /
              ErrorDocument 500 /
              ErrorDocument 503 /

              when i tries to rename files it goes to my site instead of rename files and if i removed error document code it shows as Internal Server Error . Please help me

              Comment


                #8
                Which script u using? And what err0r u getting?

                Comment


                  #9
                  i am using modified sea script and when i tried to laod rename php it redirects to site

                  Comment


                    #10
                    try to chmod it to 777

                    Comment


                      #11
                      done friend but not working

                      Comment


                        #12
                        some hosts dont allow 777 this gives an internal server error try 755

                        PHP Code:
                        foreach ($_SERVER as $server => $value)
                        {
                        echo "$server is $value<br />";
                        } 
                        

                        Comment

                        Working...
                        X