Re: Writing Problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



/*******************************************/
$fp = fopen('filename.txt', 'a+');

// The correct thing to do is:
if (! $fp)
    throw new Exception( 'Something went wrong opening the file' );

// Otherwise, you can also check with:
if (! is_resource($fp))
    throw new Exception( 'Something went wrong opening the file' );

fprintf( $fp, "whatever" );
fclose($fp);
/*******************************************/

If that fails and you aren't seeing any errors, I would try this prior to
the fopen() call:
if (is_writeable('/full/path/to/filename.txt'))
    echo "File is writeable." . PHP_EOL;

If is_writeable() returns false you need to look more closely at your
permissions.
If is_writeable() returns true and you still can't write to it, you would
then be in a very strange situation.


One other possible thing to try is to put the output of fprintf() into a
variable and echo that variable, just to make sure everything is working
fine there, but at a glance that all looks ok.

-Matt


On Tue, Aug 26, 2014 at 8:12 PM, Ethan Rosenberg <
erosenberg@xxxxxxxxxxxxxxxxxxxx> wrote:

> On 08/26/2014 09:19 PM, Matt Pelmear wrote:
>
>> Do you check whether $fh2 is a resource after you fopen()?
>>
>> <snip>
>>
>
>  Do you check whether $fh2 is a resource after you fopen()?
>  How?
>
>      TIA
>>
>>     Ethan
>>
>>     --
>>     PHP Database Mailing List (http://www.php.net/)
>>     To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux