<?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);
}
}
}
?>
这是我的代码…它在第14行的C:'xampp'htdocs'mywork'creating-folder'1.php
中显示了Fatal error: Call to undefined function copydir()
。但是,当我从copydir("test",$get_folder);
复制到closedir($dir_handle);
在单独的文件,它的工作完美,但不是$get_folder需要给一些静态名称
使用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);
}
?>
// Will copy foo/test.php to bar/test.php
// overwritting it if necessary
copy('foo/test.php', 'bar/test.php');
这行得通:
foo();
function foo() { ... }
这个不会:
if (...) {
foo();
function foo() { ... }
}
这将:
if (...) {
function foo() { ... }
foo();
}
一般来说,在调用函数之前,需要声明函数。例外是第一个例子中普通的全局定义函数;这些在执行前的解析步骤中被处理。由于您的函数声明在if
语句中,因此是有条件的,因此需要首先计算if
条件和整个代码。当代码被求值时,您试图调用一个尚未声明的函数。