E
E
Express7772016-04-15 10:57:00
PHP
Express777, 2016-04-15 10:57:00

How to properly open a file in PHP on IIS?

You need to open the file in IIS.
This code opens without problems

$filename = 'C:/web/files/test.txt'';
file_get_content($filename);

But this code throws an error:
$filename = $_SERVER['DOCUMENT_ROOT'] . '/files/test.txt';
file_get_content($filename);

Warning: file_get_contents(C:\web/files/test.txt): failed to open stream: No such file or directory in

Tried this option:
$filename =  addslashes($_SERVER['DOCUMENT_ROOT'] . '\\files\\test.txt');
file_get_content($filename);

But also a mistake.
What is the correct way to open this file in IIS?
Windows Server 2008 R2
PHP 5.6

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kinyakin, 2016-04-15
@rkgrep

You can try doing str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']); - once with straight lines initially works.
But I wouldn't recommend using DOCUMENT_ROOT at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question