PHP does not recognize a file name with an apostrophe in it

I am currently trying to check with PHP if a file exists. The current file that I am trying to check if it exists contains an apostrophe, the file is called: 13067-AP-03 A - situation projetée.pdf.

The code I use to check if a file exists:

$filename = 'C:/13067-AP-03 A - Situation projetée.pdf';

if (file_exists($filename)) 
{
    echo "The file exists";
} else 
{
    echo "The file does not exist";
}

The problem that I am facing right now is that whenever I try to check if a file exists, I get a message that it does not exist. If I continue deleting é, I get a message that the file exists.

It seems that PHP somehow does not recognize the file if it has an apostrophe. I tried the following:

urlencode($filename);
addslashes($filename);
utf8_encode($filename);

None of them worked. I also tried:

setlocale(LC_ALL, "en_US.utf8");

, , PHP, : 13067-AP-03 A - projet e.pdf

, :

$filename = iconv( "CP437", 'UTF-8', $filename);

, - . .

, , script Windows.

: Sublime Text 3 . , PHP.

, , , , :

13067-AP-03 A - Situation projet e.pdf

, , , file_get_contents. file_get_contents .

+4
3

, PHP Windows. Windows Windows, .

https://bugs.php.net/bug.php?id=47096

, ( ) Unicode $u (, UTF-8), Windows, , setlocale (LC_CTYPE, 0), , $u ; , PHP. Dot.

CP932, , chcp cmd.

, , :

$filename='C:\Users\Frederick\Desktop\13067-AP-03 A - Situation projetée.pdf';
$filename=mb_convert_encoding($filename, 'CP932', 'UTF-8');
var_dump($filename);
var_dump(file_exists($filename));

! ? CP932 é!

https://msdn.microsoft.com/en-us/library/windows/desktop/dd317748%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

NTFS Unicode. , FAT12, FAT16 FAT32 OEM.

Windows UTF-16LE, Unicode Microsoft, . PHP UTF-16LE.

, , , Windows. , PHP .

+1

, "UTF-8 "

BOM - , , , , , little-endian big-endian, PHP .

-1

Try this when running your php file:

<?php
header('Content-Type: text/html; charset=utf-8');
?>
-2
source

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


All Articles