PHP 移动图片功能
PHP Move images function
需要帮助。
function move_images($dir_source,$dir_target){
$files = glob($dir_source);
foreach($files as $file){
if(is_file($file))
copy($file,$dir_target.basename($file));
unlink($file);
}
return true;
}
move_images('temp/*','../images/');
我收到这条消息:
Warning: Invalid argument supplied for foreach() in
/home/scrapboo/public_html/inc/functions.php on line 75
实际上,当 "temp" 目录中有文件时,它工作得很好。那么,当temp为空时如何跳过这个?
谢谢
Actually, it's working good when there's a files in "temp" directory. So, how to skip this when temp is empty?
无需检查 directory/array 是否为空,如果是,它就不会遍历您的 foreach 循环。
但是你必须确保你的目录是可读的,你可以用is_readable()
检查一下。
需要帮助。
function move_images($dir_source,$dir_target){
$files = glob($dir_source);
foreach($files as $file){
if(is_file($file))
copy($file,$dir_target.basename($file));
unlink($file);
}
return true;
}
move_images('temp/*','../images/');
我收到这条消息:
Warning: Invalid argument supplied for foreach() in /home/scrapboo/public_html/inc/functions.php on line 75
实际上,当 "temp" 目录中有文件时,它工作得很好。那么,当temp为空时如何跳过这个?
谢谢
Actually, it's working good when there's a files in "temp" directory. So, how to skip this when temp is empty?
无需检查 directory/array 是否为空,如果是,它就不会遍历您的 foreach 循环。
但是你必须确保你的目录是可读的,你可以用is_readable()
检查一下。