SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    file_put_contents() file owner in OSX

    My php script is running with owner "denny" as reported by
    Code PHP:
    but the files it creates with
    Code PHP:
    show the owner of the files as "www" as reported by Get Info in Finder.

    Code PHP:
    does let let me change the owner: "Warning: chown() [function.chown]: Operation not permitted in ..."

    How do I tell php to create the file with owner "denny"?
    Denny Schlesinger
    web services

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,329
    Mentioned
    191 Post(s)
    Tagged
    4 Thread(s)
    The owner of the PHP Process is 'www' (you can verify this with the `ps` command a the command-line).
    If it is important for 'denny' to have access to the files (although, unless 'denny' is an administrator of the machine, you should let your PHP application control all files and access to them for each user) and that is a user on the system, you can add 'denny' and 'www' to the same group.

    I believe if you provide a little more detail about what you are trying to accomplish (the "Why" behind this) there are many here who can point you to success.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    get_current_user is a bit of a misnomer - I think you'll find that it gets 'denny' because thats the owner of the php file currently in execution. However, the actual user executing the PHP script is 'www'.
    You'll need to chown, so www will need sudo capability.

    Is this for a local machine, or are you trying to do this on an actual deployment?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParkinT View Post
    I believe if you provide a little more detail about what you are trying to accomplish (the "Why" behind this) there are many here who can point you to success.
    It's a little word processor web app. I write the text with BBEdit
    Code HTML4Strict:
    <!-- text starts here -->
    <br><br>
    <h1>Mantenimiento de Desages</h1>
    <br>
    <p>Estimados Copropietarios:</p>
    <p>Para minimizar los inconvenientes con los desages de los apartamentos la Junta de Condominio ha recopilado las siguientes sugerencias.</p>
    <h2>1.- Uso apropiado</h2>
    and the script displays the final letter on the screen and saves the completed letter to a folder.

    It works fine but the file is saved with owner "www" meaning it can't be edited in BBEdit until I change the owner which I can do but it's a PITA.

    This is running on my laptop. On my server I have an issue with permissions that I need to resolve with my web host.
    Denny Schlesinger
    web services

  5. #5
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    get_current_user is a bit of a misnomer - I think you'll find that it gets 'denny' because thats the owner of the php file currently in execution. However, the actual user executing the PHP script is 'www'.
    You'll need to chown, so www will need sudo capability.

    Is this for a local machine, or are you trying to do this on an actual deployment?
    For now it's on my laptop. What do I "chown?" (yes I have sudo capability).
    Denny Schlesinger
    web services

  6. #6
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    On my server I have an issue with permissions that I need to resolve with my web host.
    Correction, on the server there is no problem with the permissions but I do have a problem converting diacritics to html (accents, etc. --> <-- characters we use in Spanish)
    Denny Schlesinger
    web services

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    On your laptop, if -www- has sudo capability, you can drop him to the command line and exec the chown.

    What are you trying to convert that doesnt get converted by htmlentities?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    What are you trying to convert that doesnt get converted by htmlentities?
    On the contrary, it converts too much! Like "<" and ">" which ruins the html!

    Some functions have an exclusion or inclusion parameter but not htmlentities() that I know of.
    Denny Schlesinger
    web services

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    So when you htmlspecialchars_decode the result on the other end, it comes out wrong?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by StarLion View Post
    So when you htmlspecialchars_decode the result on the other end, it comes out wrong?
    I don't use htmlspecialchars_decode. I need to explain this hack.

    I believe that in a ideal world we should only have three desktop apps: a browser, an ftp package, and a text editor. Everything else should be a web app. Since PCs are now servers, we can use the web apps locally which is what I'm doing with the one I'm testing now.

    My web app (which does not yet have a name) creates an HTML5 document which prints a letter just like a word processor document using a template for the letterhead and a text document for the letter body. In fact, the browser acts like a word processor. It's a simple script really:
    Code PHP:
    <?php
     
    $files = "/Users/username/Sites/path/to/letters/";
     
    // this is the html header and the letterhead
    $html = <<< AVILAAVILA
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    <title>Edifico Avila</title>
    <link rel="stylesheet" type="text/css" href="avila.css">
    </head>
    <body>
    <div class="logo">
    <span>edif.<span>A</span>vila</span><br>
    Avenida Buenos Aires, Los Caobos, Caracas.
    </div>
     
    AVILAAVILA;
     
    // this is the letter's body
    $html .= file_get_contents("+avila.html");
    $html .= "</body>\n</html>\n";
     
    // create a ubique file name
    $date = date ("m-d-y");
    $filename = "{$files}avila-{$date}.html";
    $append = "";
    while (file_exists ($filename)) {
        $append += 1;
        $filename = $filename = "{$files}avila-{$date}-{$append}.html";
        if ($append > 10) {
            die ("too many files already");
        }
    }
     
    // adjust some URLs for archiving
    $html1 = str_replace ("avila.css", "../avila.css", $html);
    $html1 = str_replace ('src="images/', 'src="../images/', $html1);
    $html1 = str_replace ('<body>', '<body style="border:none;">', $html1);
     
    // save the file
    if (file_put_contents ($filename, $html1) === FALSE) {
        die ("Cannot write to file ($filename)");
    }
     
    // show some feedback on the screen
    echo "<div class='no-print'>";
    echo "Success, $filename";
    echo "</div>";
     
    // display the letter
    echo $html;
     
    ?>
    The problem is that in Spanish we use diacritical marks: accents, tildes, cedillas, and umlauts () plus opening exclamation and question mark (). The best way to deal with them is to use the html entity codes. Typing the html entity codes is pita so I want to use some code to translate them. But htmlentities also converts the open and close html tags "<>" which I need to render the html correctly. I also have the option of using a BBEdit Text Factory but I prefer a php solution. I have a function for the conversion which works on my laptop but gives funny (UTF-8?) codes on my LAMP server.
    Code PHP:
    function c2html($text) {
     
        $table = array(
        '' => '&iexcl;',
        '' => '&cent;',
        '' => '&pound;',
        '' => '&copy;',
        '' => '&reg;',
        '' => '&deg;',
        '' => '&iquest;',
        '' => '&Aacute;',
        '' => '&Ccedil;',
        '' => '&Eacute;',
        '' => '&Iacute;',
        '' => '&Ntilde;',
        '' => '&Oacute;',
        '' => '&Uacute;',
        '' => '&Uuml;',
        '' => '&aacute;',
        '' => '&ccedil;',
        '' => '&eacute;',
        '' => '&iacute;',
        '' => '&ntilde;',
        '' => '&oacute;',
        '' => '&uacute;',
        '' => '&uuml;',
        '&' => '&amp;',
        '' => '&yen;');
     
        return strtr($text, $table);
     }
    Thanks for listening!
    Denny Schlesinger
    web services

  11. #11
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by captainccs View Post
    I don't use htmlspecialchars_decode. I need to explain this hack.
    You really dont need to explain it so much. You have some HTML you need to encode and store, and then decode only the html characters, leaving the diacretics.

    htmlentities
    htmlspecialchars_decode
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  12. #12
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    You really dont need to explain it so much. You have some HTML you need to encode and store, and then decode only the html characters, leaving the diacretics.
    Interesting idea! But I would have to change the workflow. Let me think about it and I'll get back to you. Thanks!
    Denny Schlesinger
    web services

  13. #13
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    You really dont need to explain it so much. You have some HTML you need to encode and store, and then decode only the html characters, leaving the diacretics.

    htmlentities
    htmlspecialchars_decode
    Brilliant!
    Code PHP:
    $html .= htmlentities(file_get_contents("+avila.html"), ENT_NOQUOTES, "iso-8859-1");
    $html  = htmlspecialchars_decode($html);
    echo $html;

    Thanks!

    BTW, one has to make sure the file itself (+avila.html) is saved as "iso-8859-1" otherwise it does not work.
    Denny Schlesinger
    web services


Bookmarks

Posting Permissions

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