doudou201701 2015-09-06 09:43
浏览 76

查找以文件夹内的字符串开头的文件

$file = glob("submission/".$iid."/".$yr."/".$sem."/".$sec."/Word/".$sid.".*");
 if ($file!=="")
{ 
    return $path."/". $file;
   break;
}

the sid is the student submitted file starting with the student id .I want tyo find the exact file from inside the folder 'word' .The file is like 211000110-Word.docx

  • 写回答

1条回答 默认 最新

  • drema2014 2015-09-06 10:05
    关注

    glob() returns an array that you need to further loop through and match the individual values against the value you are looking for.

    $files = glob("submission/".$iid."/".$yr."/".$sem."/".$sec."/Word/*.docx");
    
    $result = false; 
    
    foreach($files as $file) {
        if($file == "$sid-Word.docx"){
            $result = $file;
            break;
        }
    }
    

    Turning this into a re-usable function would be a good idea:

    function get_student_file($sid) {
        $files = glob("submission/".$iid."/".$yr."/".$sem."/".$sec."/Word/*.docx");
    
        $result = false; 
    
        foreach($files as $file) {
            if($file == "$sid-Word.docx"){
                $result = $file;
                break;
            }
        }
    
        unset($files);
    
        return $result;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度