Solved

allow me to write a file without getting a warning

Posted on 2013-01-13
4
346 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now