PHP File access

Read by lines

$hd = fopen(“$file”, “r”);

if($hd){

while(!feof($hd)){

$line = fgets($hd);

}

}

fclose($hd);

Read the whole file in

$hd = fopen(“$file”, “r”);if($hd){

$contents = fread($hd, filesize($file));

}

fclose($hd);

Read image in binary

if(!($img = fopen(“$img_path”,”rb”))){

echo “couldn’t open $img_path”;

die;

}

while (!feof($img)) {

$contents .= fread($img, 1024);

}

fclose($img);

###Header for image
header(“Cache-Control: public”);

if(eregi(“\.[jpg|jpeg]”,$file)){

header (“Content-type: image/jpg”);

header(“Content-Disposition: inline; filename=$file”);

#header(‘Content-Length: ‘ . filesize($img));

print $contents;

}