dongweihuan8610 2016-04-12 22:05
浏览 101
已采纳

如何使用dirname(__ FILE__)代替DOCUMENT_ROOT(php web server)

I have written some code for an image gallery, the code works perfectly if the application is installed in the document root folder. However various hosting companies such as C9 and many others create their do not create their sites in the DOCUMENT_ROOT. The apache server I am trying to get the app to work on has a DOCUMENT_ROOT of /user/local/websites/

I have used the command below that runs in index.php and gives me the correct path.

// full file path to app root directory

DEFINE("DOC_ROOT", dirname(__FILE__) . '/');
echo DOC_ROOT; // /home/name/public_www/subject/index.php

How can I change the statements below to use to use the output from the DEFINE command above?

$original_file = $_SERVER['DOCUMENT_ROOT'] . SITE_FOLDER_DIR . DIR_UPLOAD_IMAGE . $main_image;
$original_file_to = $_SERVER['DOCUMENT_ROOT'] . DIR_CREATE_THUMB . $main_image;
  • 写回答

1条回答 默认 最新

  • doutandusegang2961 2016-04-12 22:33
    关注

    If you check your code, you'll find similar define(.. lines for SITE_FOLDER_DIR and DIR_UPLOAD_IMAGE. They work exactly the same way.

    To change your statements, just replace $_SERVER['DOCUMENT_ROOT'] with DOC_ROOT e.g.

    $original_file = DOC_ROOT . SITE_FOLDER_DIR . DIR_UPLOAD_IMAGE . $main_image;

    Note: as of PHP 5.3, there's no need to use dirname(__FILE__), you can simply use __DIR__ e.g.

    define("DOC_ROOT", __DIR__ . '/');

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable