/** * Open file. * * The constructor calls the fopen function to open the file handle and * throws a T_Exception_File on failure. The input $mode is also checked * for portability (it should include the 'b' binary indicator so original * line endings are preserved). The input modes available are: * * 'rb' reading only. * 'wb' writing only, truncate or create file. * * @param T_File_Path $fname full path to file * @param string $mode open mode (including 'b' indicator) */ function __construct(T_File_Path $fname, $mode) { if (strcmp('wb', $mode) == 0) { $this->fswap = $fname; $fname = new T_File_Path($fname->getDirName(), uniqid(rand(), true), null); // ^ make a tmp file in same dir as target } parent::__construct($fname, $mode); }
/** * Rename the current file to a new filename. * * @param T_File_Path $path new filepath for file */ function rename(T_File_Path $path) { if (T_WINDOWS && $path->exists()) { $path->delete(); /* required for windows, but weakens application as possibility of failure to rename resulting in just file deletion */ } $ok = @rename($this->getPath(), $path->__toString()); if (!$ok) { $msg = 'rename to ' . $path->__toString() . ' failed'; throw new T_Exception_File($this->getPath(), $msg); } $this->dir = $path->getDirName(); $this->filename = $path->getFilename(); $this->mime = $path->getMime(); return $this; }