Jump to: navigation, search

Php fpassthru

From w3cyberlearnings

Contents

PHP function fpassthru

This function outputs all remaining data on a file pointer. If you just want to dump the file content without first modify the file or seeking to a particular offset, you may want to readfile().

Syntax fpassthru

handle is a file handle and it is created by fopen() function.

fpassthru(handle);

Note

Read until the EOF of a file from the current file pointer and write the results to the output buffer. When you have already written data to the file, you may need to call rewind() function to reset the file pointer to the beginning.

Example 1

<?php

$fh = fopen("http://www.woowood.com", "r");
fpassthru($fh);
fclose($fh);
?>

Example 2

<?php

$file = '/var/www/webpage/content.logs';

$fh = fopen($file, "rb");

if ($fh) {
	$size = filesize($file);
	$name = basename($file);
// send the right headers

	header("Pragma:no-cache");
	header("Cache-Control: no-cache, must-revalidate");
	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename=\"" . $name . "\"");
	header("Content-length: $size");

	fpassthru($fh);
}
exit;
?>

Example 3

<?php
$name = '/home/www/webpage/girl.png';
$fh = fopen($name, 'rb');

// send the right headers
header("Content-Type: image/png");
header("Content-Length: " . filesize($name));

// dump the picture and stop the script
fpassthru($fh);
exit;

?>

Related Links


basename-- chgrp-- chmod-- chown-- clearstatcache-- copy-- delete-- dirname-- disk_free_space-- disk_total_space-- diskfreespace-- fclose-- feof-- fflush-- fgetc-- fgetcsv-- fgets-- fgetss-- file_exists-- file_get_contents-- file_put_contents- file-- fileatime-- filectime-- filegroup-- fileinode-- filemtime-- fileowner-- fileperms-- filesize-- filetype-- flock-- fnmatch-- fopen-- fpassthru-- fputcsv-- fputs-- fread-- fscanf-- fseek-- fstat-- ftell-- ftruncate-- fwrite-- glob-- is_dir-- is_executable-- is_file-- is_link-- is_readable-- is_uploaded_file-- is_writable-- is_writeable-- lchgrp-- lchown-- link-- linkinfo-- lstat-- mkdir-- move_uploaded_file-- parse_ini_file-- parse_ini_string-- pathinfo-- pclose-- popen-- readfile-- readlink-- realpath_cache_get-- realpath_cache_size-- realpath-- rename-- rewind-- rmdir-- set_file_buffer-- stat-- symlink-- tempnam-- tmpfile-- touch-- umask-- unlink--

Navigation
Web
SQL
MISC
References