note 109758 added to function.symlink

From: Date: Fri, 17 Aug 2012 10:59:36 +0000
Subject: note 109758 added to function.symlink
Groups: php.notes 
Request: Send a blank email to php-notes+get-190112@lists.php.net to get a copy of this message
On Linux with PHP 5.4.5 i run into a strange Problem when creating a symlink. My script tests with is_link() and is_file() for a symlink and if its not exists, creating this with symlink. So far no problems. But if i manual delete this symlink and this script runs short after, the script does not found the symlink as aspected. But the script fails when creating the symlink with: "symlink(): File exists" <?php if(is_link($symfile) and is_file($symfile)) echo 'yah!'; else symlink($orginalfile, $symfile); // error :( ?> clearstatcache() does not work, as aspected, because is_link/is_file already works. But I figured out a short workaround with using rename: <?php if(is_link($symfile) and is_file($symfile)) echo 'yah!'; else{ $randfile = 'anywhere_with_rights/random_name'; symlink($orginalfile, $randfile); rename($randfile, $symfile); // voilà ... no error } ?> ---- Server IP: 87.106.1.137 Probable Submitter: 217.91.162.102 ---- Manual Page -- http://www.php.net/manual/en/function.symlink.php Edit -- https://master.php.net/note/edit/109758 Del: integrated -- https://master.php.net/note/delete/109758/integrated Del: useless -- https://master.php.net/note/delete/109758/useless Del: bad code -- https://master.php.net/note/delete/109758/bad+code Del: spam -- https://master.php.net/note/delete/109758/spam Del: non-english -- https://master.php.net/note/delete/109758/non-english Del: in docs -- https://master.php.net/note/delete/109758/in+docs Del: other reasons-- https://master.php.net/note/delete/109758 Reject -- https://master.php.net/note/reject/109758 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190112) next »