Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.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
PHP ReadFile与空格有关的问题_Php_Jquery_Apache_Jquery File Upload_Blueimp - Fatal编程技术网

PHP ReadFile与空格有关的问题

PHP ReadFile与空格有关的问题,php,jquery,apache,jquery-file-upload,blueimp,Php,Jquery,Apache,Jquery File Upload,Blueimp,有一点PHP的问题,我现在被卡住了。我有一个名为download.php的文件,可以安全地访问存储在服务器上一个私人文件夹中的文件下载。i、 e.高于httpd的1级 代码如下所示 $Document = new Documents($DID); $file = $Document->getfilewithdir(); header("Content-Description: File Transfer"); header

有一点PHP的问题,我现在被卡住了。我有一个名为download.php的文件,可以安全地访问存储在服务器上一个私人文件夹中的文件下载。i、 e.高于httpd的1级

代码如下所示

        $Document = new Documents($DID);

        $file = $Document->getfilewithdir();

        header("Content-Description: File Transfer");
        header("Content-length: " . $Document->getfilesize());
        header("Content-type: " . $Document->getfiletype());
        header("Pragma: public");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-disposition: attachment; filename=\"" . basename($Document->getfilename()) . "\"");

        readfile($file);
        exit;
在哪里

$Document->getfilewithdir返回类似于/Applications/MAMP/htdocs/Portal\u QCNW/private/Portal\u files/filename.docx的内容

$Document->getfilename返回类似filename.docx的内容

额外代码包括:

    function setfilename($Val)
    {
        $this->c_Filename = $Val;
    }

    function getfilename()
    {
        return $this->c_Filename;
    }

    function getfilewithdir()
    {
        $path_parts = pathinfo($this->geturl());
        $file_name  = $path_parts['basename'];

        return FILELOC . $file_name;
    }
如果文件名中没有空格,这一切都可以,但如果文件名中有空格,即file name.docx或filename 1.docx,则readfile语句返回failed to open stream。我能做些什么来绕过这个问题并处理文件名中的空格

我过去常常上传文件,如果我在上传阶段删除空格,可能会有一些东西

任何想法和建议都很好

问候


詹姆斯谢谢你的帮助。我检查了代码并简化了它。因为我传递的是一个URL文件名,所以它被格式化为URL而不是字符串

现在一切都好了


James

请发布文档类的代码;这就是问题所在。或者在发生错误的实例中,$file的值我已经用请求的代码更新了原始代码。