Subject: failed to open stream: Permission denied

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    Subject: failed to open stream: Permission denied

    Hi,

    when i run my code it gives error as

    fopen(lib/providers//provider.RVLogi c.php): failed to open stream: Permission denied in F:\Facebook\fur niture11\Data Mining\public_h tml\lib\inc\fun ctions.lib.php

    Line 673 : trigger_error(" Failed to open stream to $filename. Permission denied!", E_USER_ERROR);

    could you plz tell the solution for how to avoid that errors

    [PHP]

    // Define Needed Function
    if(!function_ex ists('file_put_ contents'))
    {
    if (!defined('FILE _USE_INCLUDE_PA TH'))
    define('FILE_US E_INCLUDE_PATH' , 1);

    if (!defined('LOCK _EX'))
    define('LOCK_EX ', 2);

    if (!defined('FILE _APPEND'))
    define('FILE_AP PEND', 8);

    function file_put_conten ts($filename, $data, $flags = NULL)
    {
    //if(!file_exists ($filename)) trigger_error(" File $filename doesn't exist!", E_USER_ERROR);

    if(!isset($data )) trigger_error(" No value provided for required parameter \$data!", E_USER_ERROR);

    if(empty($data) && $data != 0) trigger_error(" Empty value passed for parameter \$data!", E_USER_ERROR);

    if (FALSE === ($fp = @fopen($filenam e, $flags & FILE_APPEND ? 'a' : 'wb', $flags & FILE_USE_INCLUD E_PATH)))
    {
    trigger_error(" Failed to open stream to $filename. Permission denied!", E_USER_ERROR);
    return FALSE;
    }

    if ($flags & LOCK_EX)
    if (!flock($fp, LOCK_EX))
    trigger_error(" Exclusive lock to $file was not obtained!", E_USER_WARNING) ;

    $length = strlen($data);
    $bytes = 0;

    if (FALSE === ($bytes = @fwrite($fp, $data)))
    {
    trigger_error(" Failed to write $length bytes to $filename!", E_USER_ERROR);
    return FALSE;
    }

    fclose($fp);

    if($bytes != $length)
    {
    trigger_error(" Only $bytes of $length bytes were written to $filename! Possibly out of disk space.", E_USER_WARNING) ;
    return FALSE;
    }

    return $bytes;
    }
    }

    [/PHP]
    Last edited by pbmods; Jul 4 '08, 03:30 PM. Reason: Fixed CODE tags.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You forgot to close the PHP tag: [/PHP]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Swethak.

      To avoid this error, you have to modify permissions on the directory that will contain the file in question so that it is writeable by the webserver process.

      Comment

      Working...