/* Prototype : bool unlink(string filename[, context context]) * Description: Delete a file * Source code: ext/standard/file.c * Alias to functions: */ echo "*** Testing unlink() : variation ***\n"; $workDir = "unlinkVar8.tmp"; $tmpDir = "subDir.tmp"; $dirToLinkTo = $workDir . '/' . "linkme.tmp"; mkdir($workDir); $cwd = getcwd(); mkdir($dirToLinkTo); $dirs = array($workDir . '/' . $tmpDir, './' . $workDir . '/' . $tmpDir, $workDir . '/../' . $workDir . '/' . $tmpDir, $cwd . '/' . $workDir . '/' . $tmpDir, $cwd . '/./' . $workDir . '/' . $tmpDir, $cwd . '/' . $workDir . '/../' . $workDir . '/' . $tmpDir, $workDir . '//' . $tmpDir, $cwd . '//' . $workDir . '//' . $tmpDir); foreach ($dirs as $dirToUnlink) { test_link($workDir . '/' . $tmpDir, $dirToLinkTo, $dirToUnlink, true); //soft link //cannot test hard links unless you are root. } echo "\n--- try to unlink a directory ---\n"; unlink($dirToLinkTo); rmdir($dirToLinkTo); rmdir($workDir); function test_link($linkedDir, $toLinkTo, $tounlink, $softlink) { if ($softlink == true) { symlink($toLinkTo, $linkedDir); $msg = "soft link"; } else { link($toLinkTo, $linkedDir); $msg = "hard link";
//$link="http://tw.yahoo.com"; //$link="http://www.ettoday.net/news/20140427/351031.htm"; //$link=urldecode("http%3a%2f%2fgoo.gl%2fLZbaPp"); //$link="https://www.facebook.com/robotclubtw"; //$link="http://tw-leaderg.leadergstaging.com/forum/index?sn=1093"; //$link="http://share.hothk.com/2014/05/blog-post_9622.html?m=1&_=1400228348899"; //$link="http://en.wikipedia.org/wiki/Caelum"; //$link="http://udn.com/NEWS/BREAKINGNEWS/BREAKINGNEWS9/8682091.shtml"; //$link="https://tw.news.yahoo.com/%E7%82%BA8%E5%8D%83%E5%85%83%E7%94%B7%E5%8B%92%E6%96%83%E5%A5%B3%E5%90%8C%E4%BA%8B-%E7%88%B6%E8%A6%AA%E7%97%9B%E6%89%B9-%E5%AF%A6%E5%9C%A8%E5%A4%AA%E5%8F%AF%E6%83%A1%E4%BA%86-080133415.html"; //$link="http://udn.com/NEWS/MAINLAND/MAI1/"; //Main code $og1 = new og(); //ob_start(); //Time test //$time_start = microtime(true); if (test_link($link)) { parser_link($link, $result); } //$time_end = microtime(true); //$time = $time_end - $time_start; //echo "Function in $time seconds\n"; //$time_end2 = microtime(true); //$time = $time_end2 - $time_end; //echo "Function in $time seconds\n"; $og1->show_og_content(); if ($og1->image != "none") { $og1->get_og_image($og1->image); } //ob_end_flush(); //Test //print_r($og_infos);
* Source code: ext/standard/file.c * Alias to functions: */ echo "*** Testing unlink() : variation ***\n"; $workDir = "unlinkVar8.tmp"; $tmpFile = "file.tmp"; $fileToLinkTo = $workDir . '/' . "linkme.tmp"; mkdir($workDir); $cwd = getcwd(); touch($fileToLinkTo); $files = array($workDir . '/' . $tmpFile, './' . $workDir . '/' . $tmpFile, $workDir . '/../' . $workDir . '/' . $tmpFile, $workDir . '/../BADDIR/' . $tmpFile, 'BADDIR/' . $tmpFile, $cwd . '/' . $workDir . '/' . $tmpFile, $cwd . '/./' . $workDir . '/' . $tmpFile, $cwd . '/' . $workDir . '/../' . $workDir . '/' . $tmpFile, $cwd . '/BADDIR/' . $tmpFile, $workDir . '/' . $tmpFile . '/', $cwd . '/' . $workDir . '/' . $tmpFile . '/', $workDir . '//' . $tmpFile, $cwd . '//' . $workDir . '//' . $tmpFile); foreach ($files as $fileToUnlink) { test_realfile($workDir . '/' . $tmpFile, $fileToUnlink); test_link($workDir . '/' . $tmpFile, $fileToLinkTo, $fileToUnlink, true); //soft link test_link($workDir . '/' . $tmpFile, $fileToLinkTo, $fileToUnlink, false); //hard link } unlink($fileToLinkTo); rmdir($workDir); function test_realfile($file, $tounlink) { touch($file); echo "-- removing {$tounlink} --\n"; $res = unlink($tounlink); if ($res === true) { if (file_exists($tounlink) === false) { echo "file removed\n"; } else { echo "FAILED: file not removed\n"; }