Results 1 to 6 of 6

Thread: How to Open a File in PHP

  1. #1
    Join Date
    Aug 2006
    Posts
    201

    How to Open a File in PHP

    I am working on project with php language. The project code contained in the Web page, even when viewing the page source. I want to know the procedure to open file in php. What are various command available in php to open file. In JavaScript if( fclose( fp )) function closed the file called fp, which is to be declare in the before starting the function...

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: How to Open a File in PHP

    The PHP code within the Web page is processed (parsed) by a PHP engine on the Web server, which dynamically generates HTML; the HTML, which contains the Web page content, If you have written data to a file from PHP, or you have a file on your server you need to read with PHP, then you can use fopen() function.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to Open a File in PHP

    Fread () reads data from an external file and reports it back to your PHP file. It read the number of bytes that you specify. fread() reads up to length bytes from the file pointer referenced by handle It is phrased as: fread ( handle, length ). You must open the file in the handle. The length is measured in bytes, with a 8192 byte maximum.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to Open a File in PHP

    Use the 'r' option to open a file as read-only. When a file is opened as read-only, the file pointer is placed in the beginning of the file and you start reading from there. The PHP function fgets () is used to read a file line by line. This will only work if the file data is stored on separate new lines, if it is not this will not produce the results you are looking for. w+ is use to Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to Open a File in PHP

    Use this code to open file in php :

    Code:
    <html>
    <body>
    
    <?php
    $file=fopen("file.txt","r");
    ?>
    
    </body>
    </html>

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: How to Open a File in PHP

    Read/Write: 'r+' > Opens a file so that it can be read from and written to. The file pointer is at the beginning of the file. Append: 'a+' > This is exactly the same as r+, except that the pointer which is appear in file is at the end of the file. The difference with 'r+' is that the file pointer is positioned at the end of the file. Write/Read: 'w+' > This is exactly the same as r+, except that it deletes all information in the file when the file is opened.

Similar Threads

  1. Replies: 5
    Last Post: 10-03-2012, 03:04 AM
  2. Office 2003 won't open via DC but will via File, open
    By krolyat in forum MS Office Support
    Replies: 1
    Last Post: 28-10-2011, 04:26 PM
  3. Replies: 6
    Last Post: 27-06-2011, 07:19 AM
  4. Replies: 4
    Last Post: 07-02-2011, 10:19 AM
  5. Replies: 4
    Last Post: 02-07-2010, 06:32 AM

Tags for this Thread

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
  •  
Page generated in 1,714,287,170.78074 seconds with 17 queries