> Online tutorial : fdopen
Showing posts with label fdopen. Show all posts
Showing posts with label fdopen. Show all posts

read file in php

read from file in php
the fread() reads from an open file.The function will stop at the end of the file or when it reaches the specified length.whichever comes first.this function the read string or false on failure
syntax

frad(file,length)

Example
<html>

<body>
<?php
$f=fopen('today.txt','r');
// today.txt must in read.php location
$fh=fread($f,"6");
echo $fh;
fclose($f);
?>
</body>
</html>

Output


fdopen



  fdopen <STDIO.H>


   fdopen associates a stream with a file handle

 Declaration:


   FILE *fdopen(int handle, char *type);

      #include <stdio.h>
      #include <share.h>
      FILE *_fsopen(const char *filename, const char *mode, int shflg);

 Remarks:


 fdopen associates a stream with a file handle obtained from creat, dup,
dup2, or open.


 Return Value:
   On success,
      fdopen, fopen, and _fsopen return a
       pointer to the newly opened stream
      freopen returns the argument stream
   On error, these functions return null
Program
#include <sys\stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

int main(void)
{
   int handle;
   FILE *stream;

   /* open a file */
   handle = open("DUMMY.FIL", O_CREAT,
                  S_IREAD | S_IWRITE);

   /* now turn the handle into a stream */
   stream = fdopen(handle, "w");

   if (stream == NULL)
      printf("fdopen failed\n");
   else
   {
      fprintf(stream, "Hello world\n");
      fclose(stream);
   }
   return 0;
}