Create browse box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kuzure
    New Member
    • Dec 2006
    • 48

    Create browse box

    Dear friends,

    I need to create a browse box for my final part of assignment. Can anyone tell me how to create a browse box?

    Appreciate for any reply. Thank you.

    Best Regards.
  • mainul
    New Member
    • Sep 2006
    • 51

    #2
    [HTML]
    <html>
    <body>
    <form name="form1" enctype="multip art/form-data" method="post" action="">
    Browse your file
    <input name="file_read " type="file" id="file_read" >
    <input type="submit" name="Submit" value="OK">

    </form>
    </body>
    </html>
    [/HTML]

    is this the code what you are looking for ?

    Best regards
    Mainul

    Comment

    • kuzure
      New Member
      • Dec 2006
      • 48

      #3
      Dear Mainul,

      Hrm, I had try to change the <html> to <?php because I need a .php, but of course, it didnt work.

      By the way, I also modifying the code cuz after I click the "OK" button, I need to store text into a text file. For instance, testing.txt.

      Thanks for the reply.

      Best Regards.

      Comment

      • mainul
        New Member
        • Sep 2006
        • 51

        #4
        Originally posted by kuzure
        Dear Mainul,

        Hrm, I had try to change the <html> to <?php because I need a .php, but of course, it didnt work.

        By the way, I also modifying the code cuz after I click the "OK" button, I need to store text into a text file. For instance, testing.txt.

        Thanks for the reply.

        Best Regards.
        well next time you should post your msg more details. now tell me what exactly you want and what code did u develop so far.

        best regards
        Mainul

        Comment

        • kuzure
          New Member
          • Dec 2006
          • 48

          #5
          Originally posted by mainul
          well next time you should post your msg more details. now tell me what exactly you want and what code did u develop so far.

          best regards
          Mainul

          Sorry for the inconvenient. haha^^

          Ok. Actually I need a web page with browse box and a "ok" button only. Then, when I click the "ok" button, the text of the browse box will store in "testing.tx t".

          I had used xampp to host a server. I can use localhost to load the web page and store a "1" to testing.txt. Here is my code.

          [HTML]<?php
          $filename = 'testing.txt';
          $somecontent = "this data will store in text file";

          // Let's make sure the file exists and is writable first.
          if (is_writable($f ilename)) {

          // In our example we're opening $filename in append mode.
          // The file pointer is at the bottom of the file hence
          // that's where $somecontent will go when we fwrite() it.
          if (!$handle = fopen($filename , 'a')) {
          echo "Cannot open file ($filename)";
          exit;
          }

          // Write $somecontent to our opened file.
          if (fwrite($handle , $somecontent) === FALSE) {
          echo "Cannot write to file ($filename)";
          exit;
          }

          echo "Success, wrote ($somecontent) to file ($filename)";

          fclose($handle) ;

          } else {
          echo "The file $filename is not writable";
          }


          ?>[/HTML]

          The testing.txt need to create manually. or else, it will appear error.

          Best Regards.

          Comment

          • kuzure
            New Member
            • Dec 2006
            • 48

            #6
            Dear Mainul,

            sorry, something forgot to tell you. The code above is only can load and it will store the text in "$someconte nt". If you use dreamreaver to open it, it is totally blank.

            Well, since I know how to store data to a file, I thought I can use the same theory to modify your code. But I'm wrong, I totally dunno how to link or command the button to do anything. haha^^

            So, the conclusion is, I need a browse box and an "ok" button. When I click on the "ok" button, the text that appear in the browse box will store in a file named "testing.tx t".

            Best Regards.

            Comment

            • mainul
              New Member
              • Sep 2006
              • 51

              #7
              Originally posted by kuzure
              Dear Mainul,

              sorry, something forgot to tell you. The code above is only can load and it will store the text in "$someconte nt". If you use dreamreaver to open it, it is totally blank.

              Well, since I know how to store data to a file, I thought I can use the same theory to modify your code. But I'm wrong, I totally dunno how to link or command the button to do anything. haha^^

              So, the conclusion is, I need a browse box and an "ok" button. When I click on the "ok" button, the text that appear in the browse box will store in a file named "testing.tx t".

              Best Regards.
              is it texbox or text area? i think there is nothing called browse box

              Comment

              • dilipeee
                New Member
                • Mar 2007
                • 1

                #8
                sir

                how to send notifications when our data matches

                Comment

                • mainul
                  New Member
                  • Sep 2006
                  • 51

                  #9
                  Try out this code. Hope you wil find your solutions.
                  save it as input.html

                  [HTML]
                  <form name="form1" method="post" action="write.p hp">
                  Enter your Name:
                  <input name="Name" type="text" id="Name" value="">
                  <br>
                  Email:
                  <input name="Email" type="text" id="Email" value="">
                  <br>
                  <input name="Phone" type="text" id="Phone" value="">
                  <br>
                  Phone:
                  <input type="submit" name="Submit" value="Submit">
                  <br>
                  </form>
                  [/HTML]

                  write.php
                  [PHP]
                  <?
                  // Define file to save to:
                  $fileLocation = 'file.txt';
                  $lastElement = array_pop($_POS T);

                  // Implode the $_POST array,
                  // Save each value in format "Value0 || Value1 || Value2" etc:
                  $savePost = implode(' || ', $_POST);

                  // Open file (defined above),
                  // Set action to 'a' for 'append' - won't overwrite existing file contents:
                  $fp = fopen($fileLoca tion,'a') or die('Could not open file.');

                  // Lock file temporarily so nobody can access it while it's being written to:
                  flock($fp,LOCK_ EX);

                  // Write $savePost to a new line in the file:
                  fwrite($fp,$sav ePost."\n");

                  // Unlock the file so it can be used again:
                  flock($fp,LOCK_ UN);

                  // Close file:
                  fclose($fp);

                  ?>
                  [/PHP]

                  read.php

                  [PHP]
                  <?

                  // Define file to read:
                  $fileLocation = 'file.txt';

                  // Read the file into an array by line:
                  $fileContents = file($fileLocat ion);

                  //Start table:
                  echo '<table><tr>';
                  echo '<td>NAME</td>';
                  echo '<td>EMAIL</td>';
                  echo '<td>PHONE</td>';
                  echo '</tr>';

                  // Loop thru the file by line:
                  foreach($fileCo ntents as $line) {
                  // Trim newline \n and other whitespace:
                  $line = rtrim($line);
                  // Explode Values into an array:
                  $values = explode(' || ', $line);
                  // Print the results:
                  echo '<tr>';
                  for($n=0; $n<count($value s); $n++) echo '<td>'.$values[$n].'</td>';
                  echo '</tr>';
                  }

                  // End table:
                  echo '</table>';

                  ?>

                  [/PHP]

                  Comment

                  • kuzure
                    New Member
                    • Dec 2006
                    • 48

                    #10
                    Dear Mainul,

                    Hrm, the code is ok until i test something. Remember I told you I wanted to build a "browse box"? it is called a "File Field" in dreamreaver. I need to get the file address and store in a text file.
                    For instance, C:\Documents and Settings\Yahoo\ YourFile.txt

                    But, when it comes to store this address, it appear this in the text file, C:\\Documents and Settings\\Yahoo \\YourFile.txt

                    Notice there are double back slash at the address. what happen?

                    The result quite funny. But it is ok for normal data such like name, email, and phone number. haha^^

                    Best Regards.

                    Comment

                    • ronverdonk
                      Recognized Expert Specialist
                      • Jul 2006
                      • 4259

                      #11
                      It is using the escape character (\) to escape funny characters, such as backslashes, single and double quotes and NULL. It is added before those characters.

                      Ronald :cool:

                      Comment

                      • kuzure
                        New Member
                        • Dec 2006
                        • 48

                        #12
                        Originally posted by ronverdonk
                        It is using the escape character (\) to escape funny characters, such as backslashes, single and double quotes and NULL. It is added before those characters.

                        Ronald :cool:

                        Erm, sorry, I dont get it. How to solve this problem anyway?

                        Actually this part has connection with another. This is the final part of my assignment, haha^^. I had posted a question that ask for help in php link with VB. But since there is no one answer my question, I decide to change a method to do my project.

                        The problem is, I will use VB to load the file that store the data that get from web page. But, if there are double slashes occur, VB will pop out an error because it doesnt understand it.

                        Hope you can give me some clue.

                        Best Regards.

                        Comment

                        Working...