Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Chris Sandrini
Chris Sandrini
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

@
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
Avatar of rgb192

ASKER

you are both correct

the pipe required me to write the entire file path

and

@
hides the warning (which does not exist now)

thanks