Read and Write file contents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #46
    Originally posted by pradeepjain
    i am jst executing the code i passed u in browser by giving http://localhost/i.html is there any other php settings tht i hve to do..
    Do you have php installed?

    what happens if you have page called test.php that has only the following code in it:

    [php]
    <?php phpInfo() ;?>
    [/php]

    Run this via //localhost/test.php and tell me what you get on screen.

    Also, what web server and O/S are you running on? There are somethingns you need to set up in IIS to get php to work.

    Cheers
    nathj

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #47
      Originally posted by nathj
      Do you have php installed?

      what happens if you have page called test.php that has only the following code in it:

      [php]
      <?php phpInfo() ;?>
      [/php]

      Run this via //localhost/test.php and tell me what you get on screen.

      Also, what web server and O/S are you running on? There are somethingns you need to set up in IIS to get php to work.

      Cheers
      nathj

      i did as u said it gave me a blank screen...

      i am using linux os and apache server...

      which php to install and how and wht r the conf details

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #48
        Originally posted by pradeepjain
        i did as u said it gave me a blank screen...

        i am using linux os and apache server...

        which php to install and how and wht r the conf details
        Hi,

        How frustrating, after all this you don't have PHP installed!

        You need to go to the main php site and figure this out there, unless someone else can help. I am running PHP on Windows and have never used Linux. The instal process for Windows uses an msi and is all self explanatory.

        Perhaps you could post another question asking for help installing php on linux, I know the LAMP (Linux Apache, MySQL, PHP) combination is very popular (if not the most popular) so you will be able to get some help on that. Though ask the question without mentioing this thread.

        Hopefully, once installed your code should work fine.

        I hope you get this resolved in time - the code will work once the environment is in place.

        Cheers
        nathj

        Comment

        • pradeepjain
          Contributor
          • Jul 2007
          • 563

          #49
          [HTML]<html>
          <head>
          </head>
          <body>
          <?php

          $filehandle = fopen("welcome. txt","r");

          if(filesize("we lcome.txt")=='0 ')
          {
          echo "file empty";
          }
          else
          {
          $line=true;

          echo '<form method=post action=action.p hp>';

          while($filehand le && $line)

          {

          $line = fgets($filehand le);

          if (!empty($line))

          {

          $str = explode(':', $line);

          echo $str[0] . ': <input type="text" name="'.$str[0].'" value="'.$str[1].'"><br />';

          }

          }



          echo '<input type=submit value= submit>';

          echo '</form>';
          }
          ?>

          </body>
          </html>

          [/HTML]

          yahoo !!! the read part is working correctly....


          but now writing back to file???

          $POST wll do it but the name of the text box???


          any ideas on this...

          Comment

          • nathj
            Recognized Expert Contributor
            • May 2007
            • 937

            #50
            Originally posted by pradeepjain
            yahoo !!! the read part is working correctly....


            but now writing back to file???

            $POST wll do it but the name of the text box???


            any ideas on this...
            Glad we finally got there on that.

            As for writing back to the file the $_POST variable is really an array, so you can loop through the array and then write to file when you hit a key() value of name or location. This should sort you out nicely.

            Have a go and if you get stuck post the code you've got and I'll have a play around with it.

            Cheers
            nathj

            Comment

            • pradeepjain
              Contributor
              • Jul 2007
              • 563

              #51
              Originally posted by nathj
              Glad we finally got there on that.

              As for writing back to the file the $_POST variable is really an array, so you can loop through the array and then write to file when you hit a key() value of name or location. This should sort you out nicely.

              Have a go and if you get stuck post the code you've got and I'll have a play around with it.

              Cheers
              nathj

              i did not get ur point...i can use $POST but whts the variable name to use ....bcos while reading i am using only str[0] for variable name. ..i need to use implode function rite!!...

              Comment

              • pradeepjain
                Contributor
                • Jul 2007
                • 563

                #52
                Originally posted by nathj
                Glad we finally got there on that.

                As for writing back to the file the $_POST variable is really an array, so you can loop through the array and then write to file when you hit a key() value of name or location. This should sort you out nicely.

                Have a go and if you get stuck post the code you've got and I'll have a play around with it.

                Cheers
                nathj

                u explian me how to do it...and i hve tht of this also...i wll use a count variable while reading and use name [count]=$str[0] and value[count] =$str[1] insie the while loop and as soon as we enter keep incrimenting count..
                so tht its jst matter of for loop and implode in write function...

                Comment

                • nathj
                  Recognized Expert Contributor
                  • May 2007
                  • 937

                  #53
                  Originally posted by pradeepjain
                  u explian me how to do it...and i hve tht of this also...i wll use a count variable while reading and use name [count]=$str[0] and value[count] =$str[1] insie the while loop and as soon as we enter keep incrimenting count..
                  so tht its jst matter of for loop and implode in write function...
                  The $_POST[] is really an associative array so yo ucan simply loop through it and for any thing where the key() is either name or location you can write an appropriate line to te text file.

                  Try something like:
                  [php]
                  foreach($_POST as $lcItem)
                  {
                  if (key() == 'name')
                  {
                  // write a line to the file using file functions
                  }
                  if (key() == 'location'
                  {
                  // write a line to the file using file functions
                  }
                  }
                  [/php]


                  I have not tried this, I am typing this whilst I play with my 9month old daughter - so that's me done for the weekend, I'll check back on monday.

                  Cheers
                  nathj

                  Comment

                  • pradeepjain
                    Contributor
                    • Jul 2007
                    • 563

                    #54
                    Originally posted by nathj
                    The $_POST[] is really an associative array so yo ucan simply loop through it and for any thing where the key() is either name or location you can write an appropriate line to te text file.

                    Try something like:
                    [php]
                    foreach($_POST as $lcItem)
                    {
                    if (key() == 'name')
                    {
                    // write a line to the file using file functions
                    }
                    if (key() == 'location'
                    {
                    // write a line to the file using file functions
                    }
                    }
                    [/php]


                    I have not tried this, I am typing this whilst I play with my 9month old daughter - so that's me done for the weekend, I'll check back on monday.

                    Cheers
                    nathj

                    wht u hve said is 100% correct ..but i cannot hard code it ....bcos i wll be not knowing wht is in the file i wll be jst knowing tht there is a file and there are 2 strings seperated by ":" .....so i wll be not knowing tht it has name ,place or something else...so i cannot use if (key() == 'name')........ i hve to dynamically read the names and write the content!!!!

                    Comment

                    • nathj
                      Recognized Expert Contributor
                      • May 2007
                      • 937

                      #55
                      Originally posted by pradeepjain
                      wht u hve said is 100% correct ..but i cannot hard code it ....bcos i wll be not knowing wht is in the file i wll be jst knowing tht there is a file and there are 2 strings seperated by ":" .....so i wll be not knowing tht it has name ,place or something else...so i cannot use if (key() == 'name')........ i hve to dynamically read the names and write the content!!!!
                      Well in that case, the key() function can still be of use to you. You write to the file key(): $_POST[key()]. This should do the trick.

                      Cheers
                      nathj

                      Comment

                      • pradeepjain
                        Contributor
                        • Jul 2007
                        • 563

                        #56
                        guys thanks to all u who hve helped me....i finished my work

                        Comment

                        • nathj
                          Recognized Expert Contributor
                          • May 2007
                          • 937

                          #57
                          Originally posted by pradeepjain
                          guys thanks to all u who hve helped me....i finished my work
                          I'm gald you got it working. Anytime you get stuck post back here - with your code and and your question.


                          Cheers
                          nathj

                          Comment

                          • pradeepjain
                            Contributor
                            • Jul 2007
                            • 563

                            #58
                            hii this is a new problem

                            I need to read a folder and then take the images from there and display it in such a way tht after a certain time the neaxt image has to be taken ..in the sense it has to rotate all the images...any basic idea to do it..

                            thanks
                            pradeep

                            Comment

                            • nathj
                              Recognized Expert Contributor
                              • May 2007
                              • 937

                              #59
                              Originally posted by pradeepjain
                              hii this is a new problem

                              I need to read a folder and then take the images from there and display it in such a way tht after a certain time the neaxt image has to be taken ..in the sense it has to rotate all the images...any basic idea to do it..

                              thanks
                              pradeep
                              Based on this scant outline I would suggest that you need to investigate the directory functions in PHP. This would enable you to create an array of images. You could loop through this array using some sort of timer (note this example would need to be adapted to control when code is executed inside a loop).

                              I have never done anything like this, but this is how I would approach the problem.

                              My recommendation is to have a go with this, or any other bsae line idea. If you get stuck I would post your code and your problem to a new thread. This one has a lot of posts on it now and people may be put off by that so you could miss out on some better help.

                              Cheers
                              nathj

                              Comment

                              • pradeepjain
                                Contributor
                                • Jul 2007
                                • 563

                                #60
                                Originally posted by nathj
                                Based on this scant outline I would suggest that you need to investigate the directory functions in PHP. This would enable you to create an array of images. You could loop through this array using some sort of timer (note this example would need to be adapted to control when code is executed inside a loop).

                                I have never done anything like this, but this is how I would approach the problem.

                                My recommendation is to have a go with this, or any other bsae line idea. If you get stuck I would post your code and your problem to a new thread. This one has a lot of posts on it now and people may be put off by that so you could miss out on some better help.

                                Cheers
                                nathj







                                hiii i needed a small help on this plzz help
                                help on this

                                Comment

                                Working...