警告:file_put_contents:无法打开流:php中没有这样的文件或目录

时间:2013-05-19 14:35:12

标签: php

<?PHP

class couty{
   public function write ($a,$b){

       @session_start();
       if(!(isset($_SESSION[`login`]) && $_SESSION[`login`] != ``)){
         echo "you must Logged in to create a PHP file";
       }
       else{
            file_put_contents($a,$b);
            exit;
       }
}
}

$c = `<!DOCTYPE HTML><HTML>
<head><title></title></head>
<body></body>
</HTML>`;

if($_SERVER[`REQUEST_METHOD`] == `POST`){
   $new = trim($_POST[`coutyv`]);
   $dir = (mkdir(`folder/$new`));
   $d = new couty();
   $d->write(`$dir/$new.php`,$c);
}
?>
<form method = `post` action = ``>
<input type = `text` name = `coutyv`/>
<input type = `submit` name = `submit`/>
</form> 

2 个答案:

答案 0 :(得分:2)

你的问题就在这里。检查您是否有这些文件夹。无论如何你的代码不好

  $dir = (mkdir(`folder/$new`));
   $d = new couty();
   $d->write(`$dir/$new.php`,$c);

答案 1 :(得分:0)

我会做的事情很少

  1. 将您的变量从$ d,$ a,$ c重命名为有意义的名称 - &gt; $ new_directory,$ output_filename等
  2. 检查$ new是否有效。
  3. 检查mkdir是否成功创建了目录。
  4. 为失败的所有情况添加错误处理。
  5. 可能会,或将来可能会发生:

    $dir = (mkdir(`folder/$new`));  <--- $new might be bad / folder might be bad / call might fail
    $d->write(`$dir/$new.php`,$c);  <--- maybe the $dir/$new.php generated a bad path.
    
    // future potential errors:
    $new = trim($_POST[`coutyv`]); <---- new might not exist, might be invalid, contain invalid