|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-05-30 06:46 UTC] tux at krageroby dot no
Description:
------------
When trying to use php copy() function on a file with a newline character in the filename, it fails to open stream.
Test script:
---------------
php -r 'copy("filename_with\r\nNewline_character", "/tmp/copytest");'
Actual result:
--------------
php -r 'copy("filename_with\r\nNewline_character", "/tmp/copytest");'
PHP Warning: copy(filename_with
Newline_character): failed to open stream: No such file or directory in Command line code on line 1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
This is not a bug. See below: Test script: -------------- <?php // Create a directory to work with mkdir("testdir", 0777); // Create a file with Windows-style newline in the file name. file_put_contents("testdir/filename_with\r\nNewline_character", "test 321"); // Read active directory $files = scandir('testdir'); // print the directories/files print_r($files); // Store the file name of the created file $created_file = $files[2]; // Attempt to copy file: echo "\n"; copy("testdir/filename_with\r\nNewline_character", "testdir/copytest"); echo "\n"; // Output files in testdir $files = scandir('testdir'); print_r($files); // Can we find "\r\n" in the file name? echo "\n"; $escaped_name = str_replace(array("\r\n"), '\r\n', $created_file); echo "created/copied filename: ". $escaped_name; echo "\n"; ?> Expected result (if bug): ------------------------- Array ( [0] => . [1] => .. [2] => filename_with Newline_character ) Warning: copy(testdir/filename_with Newline_character): failed to open stream: No such file or directory in /home/husman/Desktop/test/php/bug_67361.php on line 20 Array ( [0] => . [1] => .. [2] => copytest [3] => filename_with Newline_character ) created/copied filename: filename_with\r\nNewline_character Actual result: ------------------------- Array ( [0] => . [1] => .. [2] => filename_with Newline_character ) Array ( [0] => . [1] => .. [2] => copytest [3] => filename_with Newline_character ) created/copied filename: filename_with\r\nNewline_character Further Comments: ----------------- Maybe the file name is not being properly encoded when unpacked from the zip file?Typo in "Expected results (if bug)" in the previous post. It should be: Expected result (if bug): ------------------------- Array ( [0] => . [1] => .. [2] => filename_with Newline_character ) Warning: copy(testdir/filename_with Newline_character): failed to open stream: No such file or directory in /home/husman/Desktop/test/php/bug_67361.php on line 20 Array ( [0] => . [1] => .. [2] => filename_with Newline_character ) created/copied filename: filename_with\r\nNewline_character