Search
 
SCRIPT & CODE EXAMPLE
 

PHP

dir name php

<?php
dirname(__FILE__);
?>
Comment

php dirname

// dirname ( string $path [, int $levels = 1 ] ) : string

<?php
echo dirname("/etc/passwd") . PHP_EOL;
echo dirname("/etc/") . PHP_EOL;
echo dirname(".") . PHP_EOL;
echo dirname("C:") . PHP_EOL;
echo dirname("/usr/local/lib", 2);

// Above example outputs:

/*
	"/etc"
	"/" (or "" on Windows)
	"."
	"C:"
	"/usr"
*/
Comment

php dirname

/*
* Surely you can.
* PHP has incredible built-in functionality, which is islink() and readlink(),
* There are many functions like this. See the PHP manul to learn more about it.
*/

/*
* This code is based on Ubuntu Os and applies to other 'Linux distributions' and 'Macs 
* but if you are on Windows read the PHP manual to use this approach.
*
* Server root & Symlink path : /var/www/html/my-project
* Actual path : /home/$(whoami)/my-project
* Path to file I want to add : /home/$(whoami)/my-file
*/
<?php
  
  // Including the file without checking whether the link exists or not.
  include_once(dirname(readlink($_SERVER['DOCUMENT_ROOT'])).'/my-file');

  // including the file after checking if the link exists.
  include_once(dirname(is_link($_SERVER['DOCUMENT_ROOT'])?readlink($_SERVER['DOCUMENT_ROOT']):'alternate-path').'/my-file');

?>
	  
Comment

PREVIOUS NEXT
Code Example
Php :: seconds to days hours minutes seconds php 
Php :: read text from docx in php 
Php :: php chunk array 
Php :: php repeat string 
Php :: php date to seconds 
Php :: php parse html 
Php :: how to return 0 as true in laravel 
Php :: php check if variable is string 
Php :: wp revisions config 
Php :: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.9.1/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223 mac 
Php :: php get index of current item array_reduce 
Php :: Add 7 days to the current date in PHP 
Php :: install php 7.4 ubuntu 
Php :: how to run a specific migration in laravel 
Php :: concat and search in laravel eloquent 
Php :: composer 
Php :: laravel first or create 
Php :: php prime numbers 
Php :: laravel eloquent get last record 
Php :: add field to many to many relationship laravel 
Php :: debug $_POST 
Php :: laravel validate max file size 
Php :: sanitize user input php 
Php :: try catch in laravel 
Php :: php compare two versions return true or false if version is big 
Php :: php loop through list 
Php :: php contains substring 
Php :: sustituir caracteres especiales php 
Php :: php mysqli connect err0r 
Php :: wordpress notice 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =