2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【php】destructでのrmdirでフォルダ削除失敗と対策

Last updated at Posted at 2014-06-08
test.php
<?php

header('Content-type: text/html; charset=UTF-8');

class sample{
 private $name;
 private $a_name;
 
 function __construct($name){
  $this->name = $name;
  $this->a_name = "C:/xampp/htdocs/sample/tmp/".$this->name;//成功
  //$this->a_name = "tmp/".$name;//失敗
 }
 
 function __destruct() {
    if(@rmdir($this->a_name)){
     print("削除成功\n");
    }else{
     print("削除失敗\n");
    }
  }
 
}

$obj = new sample("aa");

?>

環境

OS:windows7 32bit (自作機)
xampp windows版1.74
PHP Version 5.3.5

解説

htdocs/sample/test.phpとし、htdocs/sample/tmp/にaaフォルダを作成しておく。
この時、destructでフォルダ削除をやってみたが、相対パスだと削除されなかった。
絶対パスに変えるとフォルダ削除ができた。

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?