Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

allow me to write a file without getting a warning

#!/usr/bin/php -q
<?php // RAY_temp_rgb192.php
mail('gmail@gmail.com','subject','body');
//error_reporting(E_ALL);
//ini_set( "display_errors", 0);
ini_set("display_errors", FALSE);
ob_start();
date_default_timezone_set('America/Chicago');


// THIS IS THE SORT OF THING THAT MIGHT BE FOUND BY THE EMAIL PIPE
$email = <<<ENDEMAIL
MIME-Version: 1.0
Received: by 10.217.5.194 with HTTP; Tue, 23 Oct 2012 07:02:46 -0700 (PDT)
Date: Tue, 23 Oct 2012 10:02:46 -0400
Delivered-To: ray.paseur@gmail.com
Message-ID: <CALik7L8mmDoneUaWdO+Or1MJFFDQ27YJtEd7Gx_hut9Th_dSww@mail.gmail.com>
Subject: A Sample Message
From: Ray <ray.paseur@gmail.com>
To: Ray <ray.paseur@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hello World
ENDEMAIL;


// A REGULAR EXPRESSION TO FIND THE FROM-EMAIL ADDRESS
$regex
= '#'         //REGEX DELIMITER
. 'From:'     // LITERAL STRING
. '.*?'       // ANYTHING OR NOTHING
. '\<'        // ESCAPED WICKET
. '(.*?)'     // GROUP OF CHARACTERS WITH EMAIL ADDRESS
. '\>'        // ESCAPED WICKET
. '#'         // REGEX DELIMITER
;

// A DATE PATTERN THAT WILL CREATE ISO-8601 FORMAT
$datep = 'Y_m_d_H_i_s_';

// ISOLATE THE FROM EMAIL ADDRESS
$from = preg_match($regex, $email, $matches);

// REMOVE DOTS
$from = str_replace('.', '_', $matches[1]);

// REMOVE @-SIGN
$from = str_replace('@', '_AT_', $from);

// PREFIX DATETIME AND SUFFIX FILE TYPE
$file = date($datep) . $from . '.txt';


// WRITE THE FILE
//file_put_contents($file, $email);
//echo "FILE: <b>$file</b> WRITTEN";

Open in new window


hostgator shared hosting


file_put_contents($file, $email);

when this line is uncommented I get an warning in the gmail


PHP Warning:  file_put_contents(2013_01_13_20_42_01_ray_paseur_AT_gmail_com.txt): failed to open stream: Permission denied in /folder/pipe.php

even though the file is written


I want to suppress the writing of warning because gmail sends me a failure email back
0
rgb192
Asked:
rgb192
  • 2
2 Solutions
 
Chris SandriniSenior System EngineerCommented:
you can supress the message by adding an @ as a prefix of your function

@file_put_contents($file, $email);

Open in new window

0
 
gr8gonzoConsultantCommented:
I'm very surprised that the file is written if you are getting that message. Are you absolutely 100% certain that the file is being written?
0
 
rgb192Author Commented:
@
suppresses the warning and the gmail error email


the file is not being written: when I use a pipe (via email)
but gets written when I run file in browser
0
 
rgb192Author Commented:
you are both correct

the pipe required me to write the entire file path

and

@
hides the warning (which does not exist now)

thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now