Try to write files using php5 on Linux

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthias Braun

    Try to write files using php5 on Linux

    Help!

    I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
    the hard drive using the following command:

    $filename = "test.txt";
    if (!file_exists($ filename))
    touch($filename );
    if (is_writable($f ilename))
    $myfile = fopen( $filename,'w+') ;
    else
    {
    echo "Cannot write to file ($filename)";
    exit(1);
    }

    The script neither creates a file nor open it for writing. When using
    the same script on Windows everything works fine so I think it is a
    permission problem.

    Thanks in advance,

    Matthias
  • Riccardo Natali

    #2
    Re: Try to write files using php5 on Linux

    Matthias Braun wrote:
    check the owner:group permission on the folder/file
    if (!($fp = fopen(TEMPLATE_ PATH.$path.'/'.$file, 'w')))
    {
    echo "ERROR open file";
    } else {
    fwrite($fp, $content);
    fclose($fp);
    }

    Bye

    R

    Comment

    • Ken Robinson

      #3
      Re: Try to write files using php5 on Linux



      Matthias Braun wrote:[color=blue]
      > Help!
      >
      > I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
      > the hard drive using the following command:
      >
      > $filename = "test.txt";
      > if (!file_exists($ filename))
      > touch($filename );
      > if (is_writable($f ilename))
      > $myfile = fopen( $filename,'w+') ;
      > else
      > {
      > echo "Cannot write to file ($filename)";
      > exit(1);
      > }
      >
      > The script neither creates a file nor open it for writing. When using
      > the same script on Windows everything works fine so I think it is a
      > permission problem.[/color]

      Remember on Linux, the Apache web server runs as a process with very
      little priveleges. If you need it to write to a file, the directory
      which the file will be in needs to be writeable by everyone.

      Ken

      Comment

      • Jerry Stuckle

        #4
        Re: Try to write files using php5 on Linux

        Matthias Braun wrote:[color=blue]
        > Help!
        >
        > I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
        > the hard drive using the following command:
        >
        > $filename = "test.txt";
        > if (!file_exists($ filename))
        > touch($filename );
        > if (is_writable($f ilename))
        > $myfile = fopen( $filename,'w+') ;
        > else
        > {
        > echo "Cannot write to file ($filename)";
        > exit(1);
        > }
        >
        > The script neither creates a file nor open it for writing. When using
        > the same script on Windows everything works fine so I think it is a
        > permission problem.
        >
        > Thanks in advance,
        >
        > Matthias[/color]

        What are your permissions for the directory? Does the Apache user have write
        permission for it?


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • SOR

          #5
          Re: Try to write files using php5 on Linux

          <comp.lang.ph p , Matthias Braun , mat_braun@web.d e>
          <42e11121$0$167 77$9b4e6d93@new sread4.arcor-online.net>
          <Fri, 22 Jul 2005 17:30:41 +0200>
          [color=blue]
          > I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
          > the hard drive using the following command:
          >
          > $filename = "test.txt";
          > if (!file_exists($ filename))
          > touch($filename );
          > if (is_writable($f ilename))
          > $myfile = fopen( $filename,'w+') ;
          > else
          > {
          > echo "Cannot write to file ($filename)";
          > exit(1);
          > }
          >
          > The script neither creates a file nor open it for writing. When using
          > the same script on Windows everything works fine so I think it is a
          > permission problem.
          >[/color]

          touch($filename ); chmod($filename , 0766);

          TMK once you create a file you need to chmod it before you can write to
          it and what the folder (if any) is chmodded to is also important for non
          windows hosting .

          Comment

          • SOR

            #6
            Re: Try to write files using php5 on Linux

            <comp.lang.ph p , SOR , webmaster@spare sorrepair.co.uk .INVALID>
            <MPG.1d4b36b36a 4f80cb989d4c@no-cancel.newsread er.com>
            <Fri, 22 Jul 2005 18:17:10 +0100>
            [color=blue]
            > chmod($filename , 0766);
            >[/color]

            With regard to the webpage('filena me.php') thingy .

            Why isnt chmod(,) called something like change(,) if the name assigned
            to the function isnt important .

            Or do some things only count or have any value when it suits you ? .

            Comment

            • Ken Robinson

              #7
              Re: Try to write files using php5 on Linux



              SOR wrote (in part):
              [color=blue]
              > Why isnt chmod(,) called something like change(,) if the name assigned
              > to the function isnt important .
              >
              > Or do some things only count or have any value when it suits you ? .[/color]

              chmod is a UNIX/Linux command. AFAIK, PHP was first developed on a
              UNIX/Linux platform, so you would expect some of the familiar commands
              to be named the same.

              Ken

              Comment

              • SOR

                #8
                Re: Try to write files using php5 on Linux

                <comp.lang.ph p , Ken Robinson , kenrbnsn@rbnsn. com>
                <1122055165.644 465.216020@g43g 2000cwa.googleg roups.com>
                <22 Jul 2005 10:59:25 -0700>
                [color=blue][color=green]
                > > Why isnt chmod(,) called something like change(,) if the name assigned
                > > to the function isnt important .
                > >
                > > Or do some things only count or have any value when it suits you ? .[/color]
                >
                > chmod is a UNIX/Linux command. AFAIK, PHP was first developed on a
                > UNIX/Linux platform, so you would expect some of the familiar commands
                > to be named the same.
                >[/color]

                What a croc of shit .

                PHP has been getting developed for how many years ? .

                Is putting or adding in something like webpage() beneath them or summit
                and isnt part of php supposed to be about the ease of use .

                What do you think the chances are that a newbie will type in headers if
                they want to find out how to goto a new webpage .

                Comment

                • Geoff Berrow

                  #9
                  Re: Try to write files using php5 on Linux

                  I noticed that Message-ID:
                  <MPG.1d4b487b16 a0f749989d53@no-cancel.newsread er.com> from SOR contained
                  the following:
                  [color=blue]
                  >
                  >What do you think the chances are that a newbie will type in headers if
                  >they want to find out how to goto a new webpage .[/color]

                  It's a difficult one. People who are used to pointy clicky environments
                  (I'm not just talking about you - I see this with many of my students)
                  have got used to a lot of hand holding. PHP on the other hand is a bit
                  geeky and developed by and for people who want full control of how
                  things work. I'm sure you'd be even more frustrated by ASP.NET

                  But they can take things too far. For instance, look up 'delete' in the
                  manual.
                  --
                  Geoff Berrow (put thecat out to email)
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Try to write files using php5 on Linux

                    SOR wrote:[color=blue]
                    > <comp.lang.ph p , Ken Robinson , kenrbnsn@rbnsn. com>
                    > <1122055165.644 465.216020@g43g 2000cwa.googleg roups.com>
                    > <22 Jul 2005 10:59:25 -0700>
                    >[color=green][color=darkred]
                    >>>Why isnt chmod(,) called something like change(,) if the name assigned
                    >>>to the function isnt important .
                    >>>
                    >>>Or do some things only count or have any value when it suits you ? .[/color]
                    >>
                    >>chmod is a UNIX/Linux command. AFAIK, PHP was first developed on a
                    >>UNIX/Linux platform, so you would expect some of the familiar commands
                    >>to be named the same.
                    >>[/color]
                    >
                    >
                    > What a croc of shit .
                    >
                    > PHP has been getting developed for how many years ? .
                    >
                    > Is putting or adding in something like webpage() beneath them or summit
                    > and isnt part of php supposed to be about the ease of use .
                    >
                    > What do you think the chances are that a newbie will type in headers if
                    > they want to find out how to goto a new webpage .[/color]

                    I started learning PHP a couple of years ago. It was somewhere around my 18th
                    or 20th language - I've been programming for close to 40 years, and have
                    forgotten more languages than I remember.

                    Even without a Unix background I found PHP quite easy to learn. Like any
                    language you need to learn the operators, built-in function names and the like.
                    But it's close enough to C, C++ and Java that I had no real trouble at all.

                    And yes, I found header() quite easily in the documentation. But I guess that's
                    because I was already familiar with HTML headers.

                    As for why chmod() isn't called change() - if you just used change(), what would
                    you be changing?

                    Spend a few hours, learn the functions - just like any other language.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Ken Robinson

                      #11
                      Re: Try to write files using php5 on Linux



                      SOR wrote (in part):[color=blue]
                      > What a croc of shit .
                      >
                      > PHP has been getting developed for how many years ? .[/color]

                      PHP just celebrated it's 10th anniversary.
                      [color=blue]
                      >
                      > Is putting or adding in something like webpage() beneath them or summit
                      > and isnt part of php supposed to be about the ease of use .[/color]

                      I don't think ease of use was part of the design.
                      [color=blue]
                      >
                      > What do you think the chances are that a newbie will type in headers if
                      > they want to find out how to goto a new webpage .[/color]

                      It really depends on how you learn new programming languages and what
                      experience you've had with other languages. I seem to have an ability
                      to pick up new languages fairly quickly. I learned enough C in 4 days
                      to have my solutions to the problems given out in the 5 day class used
                      by the instructor and examples of very good programming. Before C I had
                      learned PL/1, COBOL, Fortran, Basic, and SPASM (a superset of IBM/360
                      Assembler).

                      PHP was easy for me to pick up and start using, but I am still learning
                      from other people in these forums. I starting learning PHP in 1999.

                      How did I learn. I bought books, looked at the examples, asked a lot of
                      questions and read the online manual. If you haven't looked at
                      www.php.net, you really should. There's a wealth of information and
                      examples in the manual.

                      Finally, if you don't like PHP, don't use it. There are plenty of other
                      web languages out there, some serverside (PERL, Python) and some
                      clientside (Javascript). If you want to use PHP, get used to it's
                      problems and pitfalls and enjoy the control it gives you in the
                      development of web sites.

                      Ken

                      Comment

                      • Geoff Berrow

                        #12
                        Re: Try to write files using php5 on Linux

                        I noticed that Message-ID: <T9WdnUo9P8uUK3 zfRVn-pg@comcast.com> from
                        Jerry Stuckle contained the following:
                        [color=blue]
                        >As for why chmod() isn't called change() - if you just used change(), what would
                        >you be changing?[/color]

                        change_permissi ons() would make sense

                        --
                        Geoff Berrow (put thecat out to email)
                        It's only Usenet, no one dies.
                        My opinions, not the committee's, mine.
                        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                        Comment

                        • Jerry Stuckle

                          #13
                          Re: Try to write files using php5 on Linux

                          Geoff Berrow wrote:[color=blue]
                          > I noticed that Message-ID: <T9WdnUo9P8uUK3 zfRVn-pg@comcast.com> from
                          > Jerry Stuckle contained the following:
                          >
                          >[color=green]
                          >>As for why chmod() isn't called change() - if you just used change(), what would
                          >>you be changing?[/color]
                          >
                          >
                          > change_permissi ons() would make sense
                          >[/color]

                          Too long, for one thing. Look at the original Unix commands - all very short.
                          Remember, Unix was first created in the days of the 110 baud teletypes. A 300
                          baud modem was a luxury. 1200 baud modems cost thousands.

                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstucklex@attgl obal.net
                          =============== ===

                          Comment

                          • Geoff Berrow

                            #14
                            Re: Try to write files using php5 on Linux

                            I noticed that Message-ID: <4oqdnWHWSdvv3X _fRVn-1g@comcast.com> from
                            Jerry Stuckle contained the following:
                            [color=blue][color=green]
                            >> change_permissi ons() would make sense
                            >>[/color]
                            >
                            >Too long, for one thing. Look at the original Unix commands - all very short.
                            >Remember, Unix was first created in the days of the 110 baud teletypes. A 300
                            >baud modem was a luxury. 1200 baud modems cost thousands.[/color]

                            That was then. Besides it could be an alias.

                            I could never understand why colour could not be an alias for color in
                            HTML and CSS. Especially since HTML is a Brit idea <g>

                            --
                            Geoff Berrow (put thecat out to email)
                            It's only Usenet, no one dies.
                            My opinions, not the committee's, mine.
                            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                            Comment

                            • John Dunlop

                              #15
                              Re: Try to write files using php5 on Linux

                              Geoff Berrow wrote:
                              [color=blue]
                              > I could never understand why colour could not be an alias for color in
                              > HTML and CSS.[/color]

                              hows about ye olde 'hue', just for pernicketyness, or are we
                              getting into a gray^H^Hey area??
                              [color=blue]
                              > Especially since HTML is a Brit idea <g>[/color]

                              GO ON MY SON!!

                              --
                              Jock

                              Comment

                              Working...