Search code examples
phpfopen

fopen in php 7 with change different operating system


i create simple code that check if file exists and create one if return false in windows every thing is good and code work but when i upload the code to linux server not work because every file created twice in this order.

      if (file_exists(self::COOKIES_FOLDER.DS.$email . ".txt") === false) {
                 $fh = fopen(self::COOKIES_FOLDER.DS.$email . ".txt", 'w');  
                 fclose($fh);
            }

enter image description here


Solution

  • Seems $email contains some spaces in the end. it always good to trim emails and usernames.

    $file = self::COOKIES_FOLDER . DS . trim($email) . ".txt";
    
    if (file_exists($file) === false) {
         $fh = fopen($file, 'w');
         fclose($fh);
    }