dongxin9759 2015-03-19 10:46
浏览 65
已采纳

PHP移动图像功能

need help with this.

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/');

I got this message:

Warning: Invalid argument supplied for foreach() in /home/scrapboo/public_html/inc/functions.php on line 75

Actually, it's working good when there's a files in "temp" directory. So, how to skip this when temp is empty?

Thanks

  • 写回答

1条回答 默认 最新

  • dtj2ww9500 2015-03-19 10:58
    关注

    Actually, it's working good when there's a files in "temp" directory. So, how to skip this when temp is empty?

    No need to check if the directory/array is empty, if it would be it just won't iterate through your foreach loop.

    But you have to make sure that your directory is readable, you can check this with is_readable().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大