|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-06-25 03:23 UTC] leshi at list dot ru
Description:
------------
The example code is not working unlink (), because it does not free file handlde.
PHP: 5.2.3
rar: from pecl package
Reproduce code:
---------------
<?php
$rar_file = rar_open('1.rar') or die("Невозможно открыть архив");
$entries = rar_list($rar_file);
foreach ($entries AS $e)
{
// will work fine if it's remove
$e->extract('.');// Если это убрать, то все хорошо будет (в смысле файл удалиться)
}
// will called N+1 times, where N is the count of $e->extract()
while(rar_close($rar_file)) echo '.';// Будет успешно выполнено N+1 раз, где N количество вложеник, которые были дернуты
unlink('1.rar');
?>
Expected result:
----------------
removed file 1.rar
Actual result:
--------------
X-Powered-By: PHP/5.2.3
... (I have 2 files in archive)
Warning: unlink(1.rar): Permission denied in \test.php on line 12
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 13:00:01 2025 UTC |
Ok. I find it difficult to explain in English, I will try the case code step by step. 1. I have file 1.rar. If I try <?php unlink('1.rar');?>, it's work fine. File heve been removed. 2. Same file, code: <?php $rar_file = rar_open('1.rar') or die("Can't open file"); rar_close($rar_file); unlink('1.rar'); ?> work file again. 3. Same file, code: <?php $rar_file = rar_open('1.rar') or die("Can't open file"); $entries = rar_list($rar_file); rar_close($rar_file); unlink('1.rar'); ?> have problem "Permission denied". But if rar_close() will call twice (or more, depend on the count of file in archive), work fine. I.e. <?php $rar_file = rar_open('1.rar') or die("Can't open file"); $entries = rar_list($rar_file); while (@rar_close($rar_file)) echo '.'; unlink('1.rar'); ?> work fine. In my case, output whill be '...'. One for rar_open and one for each file in archive. It's bug, but can be resolved by cheet. Another way, unset( $entries); I.e. <?php $rar_file = rar_open('1.rar') or die("Can't open file"); $entries = rar_list($rar_file); unset($entries); rar_close($rar_file); unlink('1.rar'); ?> work fine too; 4. Same file, code: <?php $rar_file = rar_open('1.rar') or die("Can't open file"); $entries = rar_list($rar_file); foreach ($entries AS $e) { $e->extract('.'); // This is problem string. } unset($entries); rar_close($rar_file); unlink('1.rar'); ?> I have no idea how to make this work. If comment line $e->extract('.'); work fine, but I want to extract files. PHP work as apache module. While apache running file 1.rar still open. And I can't delete them. When apache stop (or restart), I can delete file. Whith PHP as CGI file still open while script runnig. I hope I understand explained. (Thanx http://www.google.com/translate_t)Wow! Suddenly.. But what about samle 4? How to make this work? Code like <?php $rar_file = rar_open('1.rar') or die("Can't open file"); $entries = rar_list($rar_file); $imax = count($entries); for($i=0;$i<$imax;$i++) { $entries[$i]->extract('.'); unset($entries[$i]); // unset each entry? That's right? } unset($entries); // unset entries array rar_close($rar_file); unlink('1.rar'); ?> still _not_ work.