__FILE__ A magic constant in PHP on Windows that does not return slashes

I am very new to PHP. I was looking for a PHP application that was developed and run on Apache. We move the application to a Windows server running php under IIS. The top of the index.php index has the following code that causes an error:

<?php
	$FileArray = explode("/",__FILE__);
	include_once("/" . $FileArray[1] . "/" . $FileArray[2] . "/theapp/api/MainTemplate.inc.php");
	include_once("/" . $FileArray[1] . "/" . $FileArray[2] . "/theapp/class/User.class.php");

?>
Run codeHide result

When I check __FILE_ with a warning, it shows all the way without a slash.

<?php
echo '<script language="javascript">';
echo 'alert("'.__FILE__.'")';
echo '</script>';
?>
Run codeHide result

, , c:\directory\subdirectory\theapp\index.php, c: directorysubdirectorytheappindex.php

, , :
: Undefined offset: 1 C:\Directory\\theapp\index.php 3

, ?

+4
2

Undefined , "$ FileArray", , ( isset)

PHP-, var_dump(), :

<?php
   var_dump(__FILE__);

PHP- . "\", - JavaScript ( PHP), :

alert("this\is\sample\text");
Hide result

escape, :

alert("this\\is\\sample\\text");
Hide result

:

<?php
    echo '<script language="javascript">';
    echo 'alert("'.str_replace('\\', '\\\\', __FILE__).'")';
    echo '</script>';

:

<?php
    echo '<script language="javascript">';
    echo 'alert("'.str_replace('\\', '/', __FILE__).'")';
    echo '</script>';

- .

+3

, , "\".

:

$FileArray = explode("/", addslashes(__FILE__));
0

Source: https://habr.com/ru/post/1658317/


All Articles