2013-05-03 12 views
0

我有一個文件夾路徑f1/f2/.f1和f2都是文件夾 f2文件夾包含somany子文件夾,說ff0,ff1,ff2,ff3。 f2還包含一個名爲copy_folder的文件夾(路徑爲f1/f2/copy_folder)。 我需要將ff0,ff1,ff2,ff3中的所有內容連同文件夾(ff0,ff1,ff2,ff3)一起剪切並複製到路徑爲f1/f2/copy_folder .ie,在所有進程之後,copy_folder應包含ff0 ,ff1,ff2,ff3及其內容resectively.Also應該被刪除舊文件夾.ie從文件夾f2如何剪切和複製文件夾中的文件到PHP 5.2中的另一個路徑?

其實我在php 5.3中做了這個功能 'copy'.eg:這是我的示例代碼 mkdir(f1.f2/copy_folder/ff0)//我在copy_folder中創建了文件夾 copy(f1/f2/ff0/t1.exe,copy_folder/ff0)//將內容複製到copy_folder中的ff0 unlink f1/f2/ff0)//通過刪除舊文件夾ff0

我做了這個在PHP 5.3.But它不在PHP 5.2.1中工作。是否有任何問題?使用zend框架工作的Iam。 蔭使用在陣列中的一些細節( '$ arrNewClosedIncidentsDetails')

   foreach($arrNewClosedIncidentsDetails as $arrNewClosedDet)  


{       //iteration of closed incident details there by taking the old path 


       $strOldPath = $config->paths->releaseattach.'/'.$arrNewClosedDet['strPatchPath']; //taking the 

舊路徑 如果(is_dir($ strOldPath))

{//如果該文件是豬病

$ strNewFolderPath = $ config-> paths-> closedreleaseattach。'/'。$ arrNewClosedDet ['strFolderName'];

//taking the new folder path to which old folder and sub files have to copied 
         mkdir($strNewFolderPath); 

                   //making the directory in new path (with old folder name) 
         chmod($strNewFolderPath, 0777); 

                 //giving permission to this created folder 
         $arrNewFolderRelatedFiles = scandir($strOldPath); 

            //scan all files from old folder 
         foreach($arrNewFolderRelatedFiles as 

$ objNewFolderRelatedFiles){//從舊文件夾遍歷所有文件

      if($objNewFolderRelatedFiles != '.' && $objNewFolderRelatedFiles != '..') 

{

         //remove default dot elements,which will present as the first and second array value 

          if (copy($strOldPath.'/'.$objNewFolderRelatedFiles, $strNewFolderPath.'/'.$objNewFolderRelatedFiles)) { 

//複製其跟蹤的所有文件複製到相應的已創建新的文件夾在新路徑中 chmod($ strNewFolderPath。'/'。$ objNewFolderRelatedFiles,0777); //連接至在新的文件夾中創建

         unlink($strOldPath.'/'.$objNewFolderRelatedFiles);            //delete the files from old folder 
           } 
           } 
         } 
         rmdir($strOldPath);                        //remove all old folders 
       } 
      } 

在此先感謝

回答

0

可以使用rename功能的所有文件給予許可。 rename(old_dir_name, new_dir_name)http://php.net/manual/en/function.rename.php

+0

謝謝u.But這個工作在PHP 5.2中嗎? – 2013-05-05 07:48:08

+0

如果您想保持安全:在本地副本上試用或備份項目。無論如何,這是一個很好的練習。它可以工作,即使在php4中也是如此。 http://php.net/manual/en/function.rename.php – 2013-05-05 14:58:49

+0

非常感謝你,我會盡力而爲。但是你能告訴我爲什麼複製不起作用嗎? – 2013-05-06 10:19:07

相關問題