Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在CodeIgniter中搜索文件时出错_Javascript_Jquery_Ajax_Codeigniter - Fatal编程技术网

Javascript 在CodeIgniter中搜索文件时出错

Javascript 在CodeIgniter中搜索文件时出错,javascript,jquery,ajax,codeigniter,Javascript,Jquery,Ajax,Codeigniter,我尝试搜索从url获取的文件时出错。我想在目录中搜索一个文件,如果匹配的控制器将返回值“ok”到浏览器,它将和从url获取的值匹配。但我在浏览器中看不到任何显示 jquery将url传输到服务器 var qr_download = function(e){ var img = $('#display').attr('src'); if(img == ''){ alert('Generate a code first!'); return; }else{ var fn =

我尝试搜索从url获取的文件时出错。我想在目录中搜索一个文件,如果匹配的控制器将返回值“ok”到浏览器,它将和从url获取的值匹配。但我在浏览器中看不到任何显示

jquery将url传输到服务器

var qr_download = function(e){
var img = $('#display').attr('src');
if(img == ''){
    alert('Generate a code first!');
    return;
}else{
    var fn = img.substr(img.lastIndexOf('/')+1,img.length-img.lastIndexOf('/'));

    $.ajax({
        url: 'download_file/' + fn,
        dataType: 'json',
        success: function(data){
            if(data.error)
                alert('Error: ' + data.error);
            if(data.success)
                alert('Success: ' + data.success);
        }
    });
    return false;
}
public function download_file($filename){
    $this->load->helper('download');
    $ext = substr(strrchr($filename,'.'),1);
    $list = array();

    if(in_array($ext,array('png','jpg','jpeg'))){
        $files = scandir('temp/');
        for($i=0;$i<count($files);$i++){
            if(is_file($files[$i]) && !in_array($files[$i],array('.','..'))){
                if($files[$i] == $filename){
                    //$content = file_get_contents(base_url().'temp/'.$files[$i]);
                    //force_download($files[$i],$content);
                    $this->result['success'] = 'ok';
                    exit();
                }
            }
        }//end for
    }else{
        $this->result['error'] = 'Not allowed file type';
    }

    echo json_encode($this->result);
}
我的控制器

var qr_download = function(e){
var img = $('#display').attr('src');
if(img == ''){
    alert('Generate a code first!');
    return;
}else{
    var fn = img.substr(img.lastIndexOf('/')+1,img.length-img.lastIndexOf('/'));

    $.ajax({
        url: 'download_file/' + fn,
        dataType: 'json',
        success: function(data){
            if(data.error)
                alert('Error: ' + data.error);
            if(data.success)
                alert('Success: ' + data.success);
        }
    });
    return false;
}
public function download_file($filename){
    $this->load->helper('download');
    $ext = substr(strrchr($filename,'.'),1);
    $list = array();

    if(in_array($ext,array('png','jpg','jpeg'))){
        $files = scandir('temp/');
        for($i=0;$i<count($files);$i++){
            if(is_file($files[$i]) && !in_array($files[$i],array('.','..'))){
                if($files[$i] == $filename){
                    //$content = file_get_contents(base_url().'temp/'.$files[$i]);
                    //force_download($files[$i],$content);
                    $this->result['success'] = 'ok';
                    exit();
                }
            }
        }//end for
    }else{
        $this->result['error'] = 'Not allowed file type';
    }

    echo json_encode($this->result);
}
public函数下载文件($filename){
$this->load->helper('download');
$ext=substr(strrchr($filename,“.”),1);
$list=array();
if(在数组中($ext,array('png','jpg','jpeg')){
$files=scandir('temp/');
对于($i=0;$iresult['success']='ok';
退出();
}
}
}//结束
}否则{
$this->result['error']='不允许的文件类型';
}
echo json_encode($this->result);
}

请帮助我解决此问题。谢谢。

仔细检查您的扫描路径。您的退出()将停止脚本的执行,您将永远无法获得“确定”输出。