Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Getting path from a file pointer
October 22, 2008, 1:53 pm
rate this thread
line to one of a number of other files based on some criteria. I have
an array of file pointers with writable files. I have a limitation
where each of these subfiles can only contain a maximum of 8000
lines. Once I reach that mark, I would like to close the current file
pointer and open a new one with an integer increment appended to the
My problem is that once I have created these file pointers, how do I
then, for an arbitrary pointer, find out what path it points to?
Ideally, I would like to get the current path for the pointer, perform
some string manipulation to get me a new filename, then close it and
open the new file in it's place so that I can continue writing. Seems
like there should be some built-in php function to get the path for a
file pointer, but I can't find it. Anyone know of a way to get this
Re: Getting path from a file pointer
Afaik, you can't get this from a resource created from fopen.
You could make a class which has the resource just as one of its
properties, where reading/writing is taken care of by propagating calls
(get/read/open/close) to a the resource, with other functions/properties
to 'remember' the extra data you want.
You could even go as far as to use stream_wrapper_register, in which
case you can largely keep the same code. Only opening of a filename has
to change to opening with your customer wrapper, but normal
fseek()/fwrite()/fclose etc. should work. In that case, you can even
automate the creation of a new file below the surface, just keeping
fwriting to the object, and let it create a new fileresource to write to
on the fly.