Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroups > Vista General

Vista - Problem Reading File when Name contains character numbers 63 ("?"),164, 186, 243, 248

Reply
 
Old 03-17-2008   #1 (permalink)
PHPBABY3


 
 

Problem Reading File when Name contains character numbers 63 ("?"),164, 186, 243, 248


I am trying to access all of the files in a directory, using
$a=opendir($dir) ; while ($file=readdir($a)) and
$b=file_get_contents($dir."/".$file). However, when $file contains
characters 63 ("?"), 164, 186, 243 or 248 $b is "". I tried
substituting each of the characters chr(0 to 255) for a single "?" in
file names but none of the resulting names created a value for $b
other than "".

How do I read these file contents?

P -

My System SpecsSystem Spec
Old 03-17-2008   #2 (permalink)


Windows Vista x64 Ultimate
 
 

Re: Problem Reading File when Name contains character numbers 63 ("?"),164, 186, 243,

Quote  Quote: Originally Posted by PHPBABY3 View Post
I am trying to access all of the files in a directory, using
$a=opendir($dir) ; while ($file=readdir($a)) and
$b=file_get_contents($dir."/".$file). However, when $file contains
characters 63 ("?"), 164, 186, 243 or 248 $b is "". I tried
substituting each of the characters chr(0 to 255) for a single "?" in
file names but none of the resulting names created a value for $b
other than "".

How do I read these file contents?

P -
First off, the "?" character is what is referred to as a wildcard character that represents 1 valid filename character at that point. The "*" wildcard represents any number of valid filename characters at that point.

In your current implementation, when using a wilcard character, the "file_get_contents" function will fail.

Can you perhaps elaborate a little more? Perhaps provide the string output of the call to " $a=opendir($dir)" so that I can see what the OpenDir command gives you.

One alternative for you is to first parse the directory for files, and place the list of found files into a string array. Then, and only then, will you parse each element in the array and use the "file_get_contents" on each element of the array, which should be a file that does not contain any wildcard characters.

Does this help?
My System SpecsSystem Spec
Old 03-23-2008   #3 (permalink)
PHPBABY3


 
 

Re: Problem Reading File when Name contains character numbers 63("?"), 164, 186, 243, 248

Here are suggestions that I have received from various sources and am
trying myself (to the extent that I know what he's talking about):

1. ? is a special symbol that shouldn't be used within a file name.
As for other symbols - 164 might require you to set a proper non-
unicode symbol table, and other symbols are just garbage, as far as i
see the ASCII table.

2. I think this is a trouble that has to do with the file system you
are using, some file systems requires prepending "\\?\" to the file
name to be able to get around it's normal file name checks.

3. If your code is working for normal files, odds are good that you
need to escape these special characters before you can read them.
Escaping these is dependent on your operating system, so the character
you'll use depends on the system you're running. If your system uses
the backslash to escape characters (ie, Linux), try writing these
characters with a leading backspace, ie:
foreach(glob("$dir/*") as $eachFile) {
$eachFile = preg_replace('/['.chr(63).chr(164).chr(186).']/', '\\\
\\\0', $eachFile);
print "$eachFile : ".strlen(file_get_contents($eachFile))."\n"; }

4. Question mark is illegal in file names on both Windows and Unix...
It is illegal on Windows, but it is quite valid in Unix. Forward
slash / is the only character that is invalid in a Unix file name.
Try replacing "?" with "%3F"

5. Try this one, just to explore some. echo(basename
($PHP_SELF)."<br>"); // returnes filename.php

6. You will need to construct a routine to preface the file read or to
actually dig into the PHP library and modify the base module for that
read.

7. Could we copy the original file to a standard name, or rename it,
without causing an error? I will look and see what ways the different
functions have of handling filenames and
pathing...
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can't Send Email Without Getting "Message Character Set Conflict" Vista mail
Hotmail "bottom" reading pane problem .NET General
Batch "Auto Adjusting" large numbers of images Vista music pictures video
re: Junk folders showing "historical" numbers... Live Mail
reading a big file line by line to be "out of memory" safe PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46