【发布时间】:2013-12-02 22:51:40
【问题描述】:
我正在使用blueimp jQuery File Upload plugin (documentation here),但在包含配置文件时遇到了问题(指示不同机器上上传目录的位置)。
这是必要的原因是我们本地开发服务器上的上传文件夹的相对路径与我们的生产服务器(使用 Capistrano 的 /shared/ 文件夹)上的不同。
所以我们处理这个问题的方法是在一个名为 constants.php 的文件中设置一个常量来表示不同机器上上传文件夹的路径,该文件从名为 config.php 的机器特定配置文件中读取。
然后我在上传处理程序 (UploaderHandler.php) 中包含 constants.php。
问题是包含UploaderHandler.php中的文件导致上传者在开始上传后输出SyntaxError: Unexpected token <(here's a screenshot)。
知道这里发生了什么吗?任何帮助表示赞赏!如果需要,我可以澄清问题:)
相关代码摘录如下:
/includes/constants.php:
<?php
# Grab machine-specific config file
include('config.php');
# Setup Constants for Steven's Machine
if ($_ENV["machine"] == "steven"){
define('WEB_DIR', "c:/wamp/www/ourproject");
define('SHARED', "c:/wamp/www/ourproject/shared");
# Setup Constants for Andrew's Machine
} elseif($_ENV["machine"] == "andy"){
define('WEB_DIR', "/Applications/MAMP/htdocs/ourproject");
define('SHARED', "/Applications/MAMP/htdocs/ourproject/shared");
# Setup Constants for Other Machines
} else {
define('WEB_DIR', realpath($_SERVER["DOCUMENT_ROOT"]));
define('SHARED', "/srv/www/ourwebsite.com/htdocs/shared");
}
?>
/includes/config.php:
<?php
# Set the name of your machine
$_ENV["machine"] = "andy";
?>
/file-uploader/server/php/UploadHandler.php
<?php
include('../../../includes/constants.php');
class UploadHandler
{
... // Some code omitted
function __construct($options = null, $initialize = true, $error_messages = null) {
$this->options = array(
'script_url' => $this->get_full_url().'/',
'upload_dir' => SHARED.'/uploads/shipping/',
'upload_url' => WEB_DIR.'/uploads/shipping/',
'user_dirs' => false,
'mkdir_mode' => 0755,
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client:
'delete_type' => 'DELETE',
'access_control_allow_origin' => '*',
'access_control_allow_credentials' => false,
'access_control_allow_methods' => array(
'OPTIONS',
'HEAD',
'GET',
'POST',
'PUT',
'PATCH',
'DELETE'
),
... // More code omitted
?>
开发者控制台输出:
<br />
<b>Notice</b>: Constant WEB_DIR already defined in <b>/Applications/MAMP/htdocs/ourproject/includes/constants.php</b> on line <b>13</b><br />
<br />
<b>Notice</b>: Constant SHARED already defined in <b>/Applications/MAMP/htdocs/ourproject/includes/constants.php</b> on line <b>14</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ourproject/includes/constants.php:13) in <b>/Applications/MAMP/htdocs/ourproject/file- uploader/server/php/UploadHandler.php</b> on line <b>1074</b><br />
{"files":[{"name":"photo (1). PNG","size":91006,"type":"image\/png","url":"\/Applications\/MAMP\/htdocs\/ourprojectuploads\/shipping\/photo%20%281%29. PNG","thumbnailUrl":"\/Applications\/MAMP\/htdocs\/ourprojectuploads\/shipping\/thumbnail\/photo%20%281%29. PNG","deleteUrl":"http:\/\/localhost:8888\/ourproject\/file-uploader\/server\/php\/?file=photo%20%281%29. PNG","deleteType":"DELETE"}]}
【问题讨论】:
标签: javascript php jquery ajax file-upload