Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 9th, 2008, 06:35 AM
Adam Nielsen
Guest
 
Posts: n/a
Default How do you get a filename from a handle/resource?

Hi all,

Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?

The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.) Once I've written my data to this file, I then
need to pass the filename on to an external command, but I can't see any
way to find out what the temporary file is called.

I've tried using fstat(), but this returns everything except the filename.

Any ideas?

Thanks,
Adam.
  #2  
Old October 9th, 2008, 08:55 AM
Janwillem Borleffs
Guest
 
Posts: n/a
Default Re: How do you get a filename from a handle/resource?

Adam Nielsen schreef:
Quote:
Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?
>
You can't, unless you write a wrapper which stores the file name.
Quote:
The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.)
>
It depends on what you mean by "abruptly terminate". When your script
crashes or manually interrupted, the temporary file won't be deleted.


JW
  #3  
Old October 9th, 2008, 08:55 AM
=?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=
Guest
 
Posts: n/a
Default Re: How do you get a filename from a handle/resource?

Adam Nielsen escribió:
Quote:
Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?
>
The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.) Once I've written my data to this file, I then
need to pass the filename on to an external command, but I can't see any
way to find out what the temporary file is called.
>
I've tried using fstat(), but this returns everything except the filename.
Use tempnam() instead:

http://es2.php.net/manual/en/function.tempnam.php


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
  #4  
Old October 9th, 2008, 01:35 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: How do you get a filename from a handle/resource?

Adam Nielsen wrote:
Quote:
Hi all,
>
Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?
>
The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.) Once I've written my data to this file, I then
need to pass the filename on to an external command, but I can't see any
way to find out what the temporary file is called.
>
I've tried using fstat(), but this returns everything except the filename.
>
Any ideas?
>
Thanks,
Adam.
>
You can't. But then the file will be deleted when you fclose() it - and
you should close a file you have open for writing before passing it off
to another program, anyway.

Rather, use tempname() to get a unique name, then open it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles