Solved

allow me to write a file without getting a warning

Posted on 2013-01-13
4
351 Views
Last Modified: 2013-01-14
#!/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
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
un1x86 earned 250 total points
ID: 38773614
you can supress the message by adding an @ as a prefix of your function

@file_put_contents($file, $email);

Open in new window

0
 
LVL 34

Assisted Solution

by:gr8gonzo
gr8gonzo earned 250 total points
ID: 38774084
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
 

Author Comment

by:rgb192
ID: 38776924
@
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
 

Author Closing Comment

by:rgb192
ID: 38776933
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question