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 ::  
Php :: rendering json in laravel 
Php :: in array php 
Php :: how to create php message 3 
Php :: symfony form submit on refresh 
Php :: file is empty in php 
Php :: php ksort 
Php :: php foreach skip to next 
Php :: laravel create resource 
Php :: check if custom post type exists 
Php :: isset 
Php :: php api connection 
Php :: laravel mailable from 
Php :: laravel sanctum instalation 
::  
Php :: softdelete laravel 
Php :: laravel request file empty 
Php :: add contact form 7 to page templat e 
:: laravel migration mediumint length 
Php :: laravel https middleware 
:: theme mod disalow wp 
Php :: codeigniter 4 radio button isset 
Php ::  
Php :: no cache hummingbird 
Php ::  
Php ::  
Php ::  
::  
ADD CONTENT
Topic
Content
Source link
Name
7+8 =