【问题标题】:$this->redirect works local but not online$this->redirect 在本地工作,但不能在线
【发布时间】:2014-09-04 19:43:27
【问题描述】:

[这是 cakephp]

在名为 PublicacionesController 的控制器中名为 getfile($id) 的函数上,我有 $this->redirect("../" . $file['file']); 重定向到文件以打开它。我已经测试过回显 $file['file'] 并且没关系。问题是它不会打开文件,而是重定向到 .../publicaciones/getfile/$id。

我看到有些人对此很感兴趣,所以我将发布整个功能:

 function getfile($id){
            Configure::write('debug', 2);

            $fileDir = opendir(APP . 'webroot' . DS . 'files');

            while($entryName = readdir($fileDir)) $files[] = $entryName;
            closedir($fileDir);

            $filesResult = array();
            $arrSort = array();

            $classTypes = array(
                'jpg' => 'img',
                'png' => 'img',
                'gif' => 'img',
                'jpeg' => 'img',
                'bmp' => 'img',
                'doc' => 'doc',
                'pdf' => 'pdf',
                'xls' => 'xls'
            );

            foreach($files as $file){
                //preg_match("/.+_([$id])_[0-9]{8}.+[doc|pdf|xls]/i",$file,$fileMatch);
                preg_match("/($id).+[doc|pdf|xls|jpg|jpeg|gif|png|bmp]/i",$file,$fileMatch);
                if(count($fileMatch)){
                    $props = explode('_',$file);
                    $ext = explode('.',$file);

                    $index = count($filesResult);

                    $filesResult['i'.$index] = array(
                        'file' => "files/{$file}",
                        'date' => date('d/m/Y',filectime(APP . "webroot/files/{$file}")),
                        'ext' => $classTypes[$ext[count($ext)-1]]
                    );

                    $fileDate = filectime(APP . "webroot/files/{$file}");
                    $index = count($filesResult)-1;
                    $arrSort['i'.$index] = $fileDate;
                }
            }

            arsort($arrSort);
            $filesResult = array_merge($arrSort,$filesResult);
            $file = $filesResult['i0'];

            //echo $file['file'];
            //die();

            $this->redirect("../{$file['file']}");
        }

这在本地运行良好,有什么想法吗?

【问题讨论】:

  • 这看起来非常非常规,如果它很容易破坏/滥用。作为你的问题证明。

标签: cakephp redirect


【解决方案1】:

问题是结束 php 标记后的空格。呜呜……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 2013-10-23
    相关资源
    最近更新 更多