Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Problem Reading File when Name contains "?"

 
   Database Help (Home) -> PHP SQL RSS
Next:  combobox and print query  
Author Message
PHPBABY3

External


Since: Mar 08, 2008
Posts: 8



(Msg. 1) Posted: Sat Mar 08, 2008 2:25 pm
Post subject: Problem Reading File when Name contains "?"
Archived from groups: alt>php>sql (more info?)

Problem Reading File when Name contains "?"

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 chr(63 or 164 or 186) $b is "". I tried substituting each
of the characters chr(0 to 255) for a single chr(63) i.e. "?" in file
names but none of the resulting names created a value for $b other
than "".

How do I read these file contents?

P -

 >> Stay informed about: Problem Reading File when Name contains "?" 
Back to top
Login to vote
J.O. Aho

External


Since: Dec 01, 2003
Posts: 164



(Msg. 2) Posted: Sun Mar 09, 2008 9:38 am
Post subject: Re: Problem Reading File when Name contains "?" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

PHPBABY3 wrote:
> Problem Reading File when Name contains "?"
>
> 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 chr(63 or 164 or 186) $b is "". I tried substituting each
> of the characters chr(0 to 255) for a single chr(63) i.e. "?" in file
> names but none of the resulting names created a value for $b other
> than "".

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. I do suggest you try a POSIX files
system


--

//Aho

 >> Stay informed about: Problem Reading File when Name contains "?" 
Back to top
Login to vote
PHPBABY3

External


Since: Mar 08, 2008
Posts: 8



(Msg. 3) Posted: Sun Mar 23, 2008 2:53 am
Post subject: Re: Problem Reading File when Name contains "?" [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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...
 >> Stay informed about: Problem Reading File when Name contains "?" 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Upgrade problem - Hi folks, I recently upgraded my db from version 3.23.49 (I think) to 4.0.23. I had previously done this on two other machines with no problems but on this server some (not all) of my MySQL user accounts have stopped working. For example one I had to...

Weird mysql_connect problem - Hello. My mysql_connect just started to give me following error today, Fatal error: Call to undefined function: mysql_connect() in ..../database_functions/db_functions.inc.php on line 11. So it seems that my php no longer finds php-mysql module...

[MySQL] hierachy problem ... - Hello, I have a table which have these fields: - id - idParent - label I would like to display each field and his children but each parent may have no child. Example: A AA AB AC B C CA CB .... I can't write the request, could you help me?....

function problem involving query - I'm trying to construct a database of old houses including the parts they are made of as roof construction, floor construction, types of windows, vaults, etc. To do that I set up several tables. One containing the house id, address, last visit, etc. For....

PHPtriad v2.2.1 removal - When I fist started using apache/php/mysql I used phptriad [a wonderful piece of kit] to get me up and running. I've used this ever since. I'm think inow of 'upgrading' to laters versions of all three applications, and have found various tutorials/Ho...
   Database Help (Home) -> PHP SQL All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]