link 


php128 apg

CREATES a hard link.





This function CREATES a hard link to the existing target with the specified name link.

This function is available on Windows™, since PHP 5.3.0.

Files scanned must be available for local access, they can not be remote.

This function requires PHP to run in an elevated mode or with the UAC, (User Account Control), disabled.

Returns TRUE on success or FALSE on failure.



<?php

bool link 
str $targetstr $link )


where,

$target Target of the link

$link 
The link name

?>

 $target 


Target of the link.



 $link 


The link name.



  1 EXERCISE   

<?php

/*

   This directory, then created, 
   will be used in the next exercises

*/

$dir2make01 =  __DIR__ '/adds';

if(!
file_exists($dir2make01))
{
@
mkdir ($dir2make01);

if(
file_exists($dir2make01))
{
echo 
'Directory created successfully';
}
else
{
echo 
'Directory can not be created';
}

}
else
{
echo 
'Directory already exists 
                       and can not be recreated'
;
}

?> 



General resources used in the next exercises:

base.zip 



Download this file and unzip it in the adds folder, then created.

Such files are shown below:



sw7.jpg

7 dwarfs apb

love.txt

Love's not time's fool, though rosy lips and cheeks within his bending sickle's compass come; or bends with the remover to remove. Let me not to the marriage of true minds if this be error and upon me proved, oh, no, it is an ever fixed mark. Which alters when it alteration finds, it is the star to every wand'ring bark, admit impediments; love is not love.

Your Wildest Dreams.m4a



lorem.txt

Portuguese: Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos, e vem sendo utilizado desde o século XVI, quando um impressor desconhecido pegou uma bandeja de tipos e os embaralhou para fazer um livro de modelos de tipos. Lorem Ipsum sobreviveu não só a cinco séculos, como também ao salto para a editoração eletrônica, permanecendo essencialmente inalterado. Se popularizou na década de 60, quando a Letraset lançou decalques contendo passagens de Lorem Ipsum, e mais recentemente quando passou a ser integrado a softwares de editoração eletrônica como Aldus PageMaker. English: Lorem Ipsum is simply a text simulation of the typography and printing industry and has been in use since the 16th century when an unknown printer took a tray of types and shuffled them to make a book of type models. Lorem Ipsum survived not only five centuries but also the leap into desktop publishing, remaining essentially unchanged. It became popular in the 1960s, when Letraset released decals containing passages from Lorem Ipsum, and more recently when it became integrated into desktop publishing software such as Aldus PageMaker.

sete anões.txt

Soneca, Dengoso, Feliz, Atchim, Mestre, Zangado e Dunga

star.png

star apb



You must save all the files shown above, in a folder: adds, which will be used in the next exercises.

If you find it convenient, you can store them in another folder, as long as you follow the paths indicated in each exercise.



  2 EXERCISE   

<?php

$link02a 
__DIR__ '/adds/';

$link02b __DIR__ '/temp/';


$trg02 $link02a '/sw7.jpg';
// MUST EXIST

$lnk02 $link02b '/sw7.jpg';
// SHOULD NOT EXIST

var_dump(link($trg02$lnk02));

?>

 RESULT   

This case produces:

bool(true)

This operation causes the image: sw7.jpg
to be stored in the folder: temp.


7 dwarfs apb

If this exercise were run again, the system will display a
Warning..., followed by a:

bool(false)



  3 EXERCISE   

<?php

$trg03 
__DIR__ '/temp/sw7.jpg';
// ALREADY EXISTS

$lnk03 =  __DIR__ '/temp/t1/sw7.jpg';
// SHOULD NOT EXIST

@var_dump(link($trg03$lnk03));

// If run again, 
// this exercise will return a Warning message
// accompanied by a FALSE.

?>

 RESULT   

For the first time this exercise is run, it will be displayed:

bool(true)

The other times the tested link already exists:

Warning...

bool(false)



  4 EXERCISE   

<?php

$trg04 
__DIR__ "/adds/love.txt";
// MUST EXIST

$lnk04a __DIR__ '/temp/love.txt';

$lnk04b __DIR__ '/temp/t1/love.txt';

var_dump(link($trg04$lnk04a));

echo 
'<br><br>';

var_dump(link($trg04$lnk04b));

// If run again,  
// this exercise will return a Warning message 
// accompanied by a FALSE. 

?>

 RESULT   

For the first time this exercise is run, it will be displayed:

bool(true)

bool(true)

The other times the tested link already exists:

Warning...

bool(false)

bool(false)



  5 EXERCISE   

<?php

$trg05 
__DIR__ "/adds/Your Wildest Dreams.m4a";
// MUST EXIST

$lnk05a __DIR__ '/temp/Your Wildest Dreams.m4a';

$lnk05b __DIR__ '/temp/t1/Your W Dreams.m4a';

var_dump(link($trg05$lnk05a));

echo 
'<br><br>';

var_dump(link($trg05$lnk05b));

?>

 RESULT   

For the first time this exercise is run, it will be displayed:

bool(true)

bool(true)

The other times the tested link already exists:

Warning...

bool(false)

bool(false)



  6 EXERCISE   

<?php

$from 
__DIR__ '/adds/';

$to __DIR__ '/temp/';

echo 
$from '<br><br>' $to '<br><br>';

$trg06 $from 'lorem.txt';
// MUST EXIST

$lnk06 $to 'blahblahblah.txt';

var_dump(link($trg06$lnk06));

?>

 RESULT   

For the first time this exercise is run, it will be displayed:

bool(true)

The other times the tested link already exists:

Warning...

bool(false)



  7 EXERCISE   

<?php

$from 
__DIR__ '/adds/';

$to __DIR__ '/temp/';

echo 
$from '<br><br>' $to '<br><br>';

$trg07 $from 'sete anões.txt';
// MUST EXIST

$lnk07 $to 'sete anões.txt';

var_dump(link($trg07$lnk07));

?> 

 RESULT   

For the first time this exercise is run, it will be displayed:

bool(true)

The other times the tested link already exists:

Warning...

bool(false)



Note that the file name used here has an accentuated character.

This may pose a problem in systems that use only the English language.

After the interactions of these exercises, on this page, we have the following configuration of folders on the generic hard disk:

c001b apb

Of course, your exercises can interact differently.