Re: Keeping file pointers open after script end

From: Date: Sat, 09 Jun 2007 20:58:21 +0000
Subject: Re: Keeping file pointers open after script end
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-256468@lists.php.net to get a copy of this message
On 6/9/07, Stut <stuttle@gmail.com> wrote:
Tijnema wrote: Is there any way to keep a file pointer open after script is finished, so that it can be access later, by passing it through session? Like this: page1.php: <?php session_start(); $fp = fopen("test.php","r"); $data = fread($fp,10); $_SESSION['fp'] = $fp; echo "<a href='page2.php'>Continue</a>"; ?> page2.php: <?php session_start(); $fp = $_SESSION['fp']; $data = fread($fp,10); // Should be bytes 11-20 ?> No. File pointers are resources, and resources cannot be stored in the session. What exactly are you trying to accomplish? By the looks of your example above you're wanting to remember where you got to in the file? Just pass the current location to the next page and use fseek to jump there after you've reopened the file. -Stut
Hmm, fseek seems cool, but what about FTP resources? If I open them with ftp_connect, do I need to fetch all data from FTP again, and then just trash all data I don't need? Tijnema


« previous php.general (#256468) next »