Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Warning: fopen why ?

    Hi,

    I have been using the following code to write a log:

    PHP Code:
    $today $today+32400+3600;  // Changing to Turkey time
    $day_dte date('Y M d - G:i:s'$today);
    $log_file "/example_path/a_log_ad_clicks.txt"
    $handle fopen("$log_file""ab"); 

    function 
    write_log($content) {
        global 
    $handle;
        
    fwrite($handle$content);        


    write_log("Write my log entry here \r\n" ); 
    Now I start getting this message, and no log opened and written to

    Warning: fopen(/home/example_path/rss/a_log_ad_clicks.txt): failed to open stream: Permission denied in /home/example_path/lin.php on line 13 Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/example_path/public_html/linker.php on line 18
    The code is still working in other scripts

    What could I have done wrong ?


    Thanks.


    .
    Last edited by jeddi; 05-23-2013 at 02:51 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    as the first part of the error suggests, you(your webserver) don't have permission to write to that file .
    you need to chmod it appropriately 0755 or 0777 or if you have shell access chown it so it is owned by your webserver
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    14
    Thanks
    0
    Thanked 1 Time in 1 Post
    u need to set $ sudo chmod 777 -R

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    Use file_put_contents() instead. It does the same job but makes it a lot easier.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    OK

    Thanks but I know what the problem is now

    For some reason when I write the file in the top directory, not rss directory
    it works fine

    .
    Last edited by jeddi; 05-23-2013 at 03:00 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    No. If you're running a file on the server and it is accessing another file on the same disk you don't access it via a url because the http protocol won't support opening of a local file and writing to it.

    You still need to use a local file path to open the file and write to it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks tangoforce

    I came to the same conclusion.
    And then solved the problem so modified my
    last post to show what I did.

    Thanks again
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •