drhozgt6007 2012-10-03 07:11
浏览 140

mkdir()函数给出无效参数错误

I'm practicing scraping data from some third party sites with an html parser. While I'm looping thru the given tags, I use the mkdir() function to create a new folder that is named after one of the variables that is being used in the loop. My code is as follows:

foreach($s->find('a') as $t)
{
    $inner = $t->plaintext;
    if(!is_dir("img/ncaa/".$team."")
    && !file_exists("/img/ncaa/".$team."/".substr($inner, 0, 4).".png"))
    {
        foreach($t->find('img') as $l)
        {
               $url = $l->src;
        }   

        mkdir("img/ncaa/".$team."");

        $img = "/img/ncaa/".$team."/".substr($inner, 0, 4).".png";
        file_put_contents($img, file_get_contents($url));
    }   
}

I get an error message reading: Warning: mkdir() [function.mkdir]: Invalid argument in

When I comment out all of the above code and simply write

mkdir("img/ncaa/Boston Celtics");

That seems to work. I thought for a bit that it may have had something to do with permissions, but it didn't.

Any suggestions?

  • 写回答

3条回答 默认 最新

  • doupa1883 2012-10-03 07:14
    关注

    Run this instead:

    foreach($s->find('a') as $t)
    {
        $inner = $t->plaintext;
        if(!is_dir("img/ncaa/".$team."")
        && !file_exists("/img/ncaa/".$team."/".substr($inner, 0, 4).".png"))
        {
            foreach($t->find('img') as $l)
            {
                   $url = $l->src;
            }   
    
            $theDir = "img/ncaa/".$team."";
            var_dump($theDir);
            mkdir($theDir);
    
            $img = "/img/ncaa/".$team."/".substr($inner, 0, 4).".png";
            file_put_contents($img, file_get_contents($url));
        }   
    }
    

    And inspect the output, it will probably reveal the error

    评论

报告相同问题?

悬赏问题

  • ¥50 vue3 + vite + electron打包找不到第三方包?
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点