Tag Archives: file

readfile

It outputs a file

Example

<?php

$file = ‘test.txt’;


if (file_exists($file)) {

   header(‘Content-Description: File Transfer’);

   header(‘Content-Type: application/octet-stream’);

   header(‘Content-Disposition: attachment; filename=’.basename($file));

   header(‘Content-Transfer-Encoding: binary’);

   header(‘Expires: 0’);

   header(‘Cache-Control: must-revalidate’);

   header(‘Pragma: public’);

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

   ob_clean();

   flush();

   readfile($file);

   exit;

}

?>

pathinfo

It returns information about a file path

Example

<?php
echo "<pre>";
print_r(pathinfo("test.ini"));
?>

Output

Array
(
[dirname] => .
[basename] => test.ini
[extension] => ini
[filename] => test
)

 

 

parse_ini_string

It parse a configuration string

Example

<?php

echo “<pre>”;

print_r(parse_ini_string(file_get_contents(“test.ini”)));

?>

Output

Array
(
[me] => phpcodez
[first] => http://www.phpcodez.com
)


“test.ini” file content

[names]

me = phpcodez


[urls]

first = “http://www.phpcodez.com”

parse_ini_file

It parses a configuration file

Example

<?php

echo “<pre>”;

print_r(parse_ini_file(“test.ini”));

?>

Output

Array
(
[me] => phpcodez
[first] => http://www.phpcodez.com
)


“test.ini” file content

[names]

me = phpcodez


[urls]

first = “http://www.phpcodez.com”

move_uploaded_file

It moves an uploaded file to a new location. It is used to validate whether the contents of $_FILES[‘name’][‘tmp_name’] have really been uploaded via HTTP, and also save the contents into another folder.

Example

<?php
 move_uploaded_file($tmp_name, $_FILES["file"]["name"]) or die("Failed");
?>