2013-05-27 42 views
-1
 <?php 
     extract($_REQUEST); 
     if(isset($_POST['submit'])) 
     { 
      $get_folder = $_POST['url']; 
     $q = mysql_query("insert into test (url) values ('$url')"); 
     if($q) 
     { 
     copydir("test",$get_folder); 
     function copydir($source,$destination) 
     { 
     if(!is_dir($destination)) 
     { 
     $oldumask = umask(0); 
     mkdir($destination, 01777); 
     umask($oldumask); 
     } 
     $dir_handle = @opendir($source) or die("Unable to open"); 
    while ($file = readdir($dir_handle)) 
     { 
     if($file!="." && $file!=".." && !is_dir("$source/$file")) //if it is file 
     copy("$source/$file","$destination/$file"); 
     if($file!="." && $file!=".." && is_dir("$source/$file")) //if it is folder 
     copydir("$source/$file","$destination/$file"); 
     } 
     closedir($dir_handle); 
     } 
     } 
     } 
     ?> 

,這是我的代碼......它顯示C:\xampp\htdocs\mywork\creating-folder\1.php致命error: Call to undefined function copydir()上線14但是,當我從copydir("test",$get_folder);在單獨的文件複製到closedir($dir_handle);它完美但不是$ get_folder需要給一些靜態的名稱複製一個目錄到另一個在PHP

回答

1

使用copy()

請注意,此功能支持開箱即用的目錄。從鏈接的文檔頁面上的評論之一的功能可能會有所幫助:

<?php 
function recurse_copy($src,$dst) { 
    $dir = opendir($src); 
    @mkdir($dst); 
    while(false !== ($file = readdir($dir))) { 
     if (($file != '.') && ($file != '..')) { 
      if (is_dir($src . '/' . $file)) { 
       recurse_copy($src . '/' . $file,$dst . '/' . $file); 
      } 
      else { 
       copy($src . '/' . $file,$dst . '/' . $file); 
      } 
     } 
    } 
    closedir($dir); 
} 
?> 
0
// Will copy foo/test.php to bar/test.php 
    // overwritting it if necessary 
    copy('foo/test.php', 'bar/test.php'); 
0

這工作:

foo(); 

function foo() { ... } 

這不會:

if (...) { 

    foo(); 

    function foo() { ... } 

} 

這將:

if (...) { 

    function foo() { ... } 


    foo(); 

} 

一般而言,您需要聲明函數之前請致電它。與第一個例子一樣,例外是純粹的,全局定義的函數;那些在執行之前的解析步驟中正在處理。由於您的函數聲明位於if語句中,因此有條件,因此需要首先對if條件以及整個代碼進行評估。當代碼被評估時,你試圖調用一個尚未聲明的函數。

+0

感謝deceze但這次的錯誤沒有顯示,但裏面的功能不能正常工作的代碼似乎是它不是內thefunction未來在所有的if條件後 – user2412295

相關問題