【问题标题】:PHP file isn't parsed and responds with application/x-httpd-php instead of JSONPHP 文件不被解析并以 application/x-httpd-php 而不是 JSON 响应
【发布时间】:2019-04-24 03:50:41
【问题描述】:

首先,除了这个文件之外,所有代码确实解析并按预期工作。

该文件是来自 CKFinder V3 的 connector.php,旨在使用 JSON 进行响应,但返回的是 PHP 代码。回应:

<?php

/*
 * CKFinder
 * ========
 * http://cksource.com/ckfinder
 * Copyright (c) 2007-2016, CKSource - Frederico Knabben. All rights reserved.
 *
 * The software, this file and its contents are subject to the CKFinder
 * License. Please read the license.txt file before using, installing, copying,
 * modifying or distribute this file or part of its contents. The contents of
 * this file is part of the Source Code of CKFinder.
 */

require_once __DIR__ . '/vendor/autoload.php';

use CKSource\CKFinder\CKFinder;

$ckfinder = new CKFinder(__DIR__ . '/../../../config.php');

$ckfinder->run();

它应该回应的一个例子是:

{"enabled":true,"s":"","c":"F799H8BWZTL","thumbs":["150x150","300x300","500x500"],"images":{"max":"2000x2000","sizes":{"small":"480x320","medium":"600x480","large":"800x600"}},"resourceTypes":[{"name":"Files","allowedExtensions":"7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip","deniedExtensions":"","hash":"31062ffc66943ba7","acl":1023,"maxSize":2097152,"hasChildren":false,"url":"\/uploads\/files\/"},{"name":"Images","allowedExtensions":"bmp,gif,jpeg,jpg,png","deniedExtensions":"","hash":"8bca000aae25ed21","acl":1023,"maxSize":2097152,"hasChildren":true,"url":"\/uploads\/images\/"}],"uploadMaxSize":2097152,"uploadCheckImages":false}

我不知道为什么这个特定的文件不想玩。

Chrome 开发工具的响应标头为 content-type: application/x-httpd-php 我没有看到任何其他具有该内容类型的文件。所有其他可用的页面都有content-type: text/html; charset=UTF-8,但没有一个以.php 结尾,因为它们是用mod_rewrite 重写的,如果重要的话。

connector.php 的权限与正常工作的站点(不同的服务器)相同。 root:root 644

我看过很多关于 AddHandler 和 AddType 的类似问题。

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

AddType application/x-httpd-php   php

我已经在 .htaccess 和 php.ini 中实现了这些,但没有任何效果。

服务器是一个运行 apache Apache/2.4.10 (Debian) 和 PHP 7.1.27 的 Docker 机器

我很高兴提供 phpinfo() 输出、Dockerfile、.htaccess 任何有帮助的东西。请让我知道相关部分。

【问题讨论】:

  • php apache 模块安装了吗?
  • @NickMaroulis 是的。我提到了其他所有东西都会解析。我刚刚发现了问题。感谢您的关注。

标签: php apache ckfinder


【解决方案1】:

Sonofa...花几个小时撞墙,发帖,2 分钟后找到它。

Docker 文件有:

echo "  <LocationMatch assets/>"; \
echo "    php_flag engine off"; \
echo "  </LocationMatch>"; \

文件的完整网址: https://dev.site.com/cms/modules/app/assets/js/ckfinder/core/connector/php/connector.php?command=Init&lang=en&id=foo

【讨论】:

  • 那个链接哪儿也去不了。
  • @tadman 当然不是……这是一个示例,展示了 locationMatch 如何匹配其中的资产段并终止解析。
  • 我不确定该链接是什么实用程序,因为它似乎无法帮助任何人更好地理解这一点。也许只包括 connector.php?... 部分是有意义的。
  • @tadman 也许你不理解答案的内容。 LocationMatch 块为其中包含资产的段关闭 php 引擎。该文件的链接显示它有一个“资产”部分并强制关闭“php引擎”。这就是为什么当所有其他文件都被解析时,这个文件没有被解析,PHP 被告知不要因为资产在路径中。我不确定如何使它更清楚。我无法将其标记为答案。
猜你喜欢
  • 2023-03-09
  • 1970-01-01
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 2021-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多