file_get_contents():行C中的文件名不能为空:xampp

时间:2013-12-16 10:29:16

标签: php file-handling

我想在进入此之前指出我是一个PHP新手,并且在最终决定我不知道我在做什么之前我一直在努力奋斗

function extract_bin($Filename, $output){
    global $template;
    global $BinColumnDelimiter;
    global $BinLineEnd;

    $decodedfile = fopen($output,'w+');
    $decodedfilecontents  = "";

    $handle = fopen($Filename, "r");

    if ($handle) {

        foreach ( $template as $ColName=>$Endians) 
            $decodedfilecontents .= $ColName.$BinColumnDelimiter;

        $decodedfilecontents .= $BinLineEnd;

        while (!feof($handle)) {
            $lastLine = '';

            foreach ($template as $ColName => $Endians){
                $hex  = bin2hex(fread($handle,$Endians));

                if ( $Endians <= 4) {
                    $val = hexdec(decodehex($hex));
                    if ( $val == 4294967295  ) $val = -1;
                    $lastLine .= $val.$BinColumnDelimiter;
                } else {
                    $lastLine .= str_replace("\t"," ",hex2str($hex)).$BinColumnDelimiter;
                }
            }

            if ( ! feof($handle))
                $decodedfilecontents .= $lastLine.$BinLineEnd;
        }

        fclose($handle);

        fwrite($decodedfile,$decodedfilecontents);
        fclose($decodedfile);
  }
  echo '<h1>'.$output.'</h1>';
  echo '<hr />';
  print_r($decodedfilecontents);
}

我一直收到这个错误:

警告:fopen():第8行的C:\ xampp \ htdocs \ rh-bin \ func.php中的文件名不能为空

我的问题是,在尝试将上传的文件作为附件传递时,我做错了什么?而且,为什么$ FileName似乎是空的?此外,并非每个人都会上传文件,所以我怎么能允许提交?

2 个答案:

答案 0 :(得分:0)

print_r($Filename)检查是否打印任何内容

答案 1 :(得分:0)

在传递给fopen()之前检查$ Filename是否为空。 //这是一种很好的做法。

根据你的问题,你的说法不是每个人都在上传文件,那么你每次使用空值调用此函数而不上传文件时也要检查并确认。

相关问题