- Создать символическую ссылку
- symlink
- Список параметров
- Возвращаемые значения
- Ошибки
- Примеры
- Смотрите также
- User Contributed Notes 20 notes
- link
- Ошибки
- Примеры
- Примечания
- Смотрите также
- User Contributed Notes 4 notes
- PHP symlink() Function
- Syntax
- Parameter Values
- Technical Details
- COLOR PICKER
- Report Error
- Thank You For Helping Us!
- Ссылку создавать файл php
- Обратная связь
- Авторизация
Создать символическую ссылку
Символическая ссылка — папка, в которой выводится содержимое из другой папки.
Создать символическую ссылку можно через функцию symlink() .
symlink('path/folder', 'path/sym_folder');
После выполнения кода выше будет создана папка «sym_folder», при открытии которой будут выводится файлы из папки «path/folder».
Если указать слеш в имени папки, то PHP вернёт ошибу «нет такого файла или папки».
symlink('path/folder/', 'path/sym_folder/'); // Warning: symlink(): No such file or directory
Если указанная символическая ссылка уже существует, то PHP вернёт ошибку «Warning: File exists».
Авторизуйтесь, чтобы добавлять комментарии
- Создание файла
- Добавить строку в файл
- Вывести содержимое файла
- Проверить файл на существование
- Изменить строку в файле
- Удалить файл
- Переименовать или переместить файл или папку
- Копировать файл
- Вывести содержимое в папке
- Создать символическую ссылку
- Скачать файл из интернета на сервер
- Соединить текстовые файлы в один файл
- Скачать файл на сервере
- Чтение XML
- Работа с JSON
- Передать в JavaScript данные в формате JSON
- Работа с CSV
- Вывод данных с Excel-файла
- Хеш файла
symlink
symlink() создаёт символическую ссылку на существующий файл target с именем link .
Список параметров
Возвращаемые значения
Возвращает true в случае успешного выполнения или false в случае возникновения ошибки.
Ошибки
Функция завершается с ошибкой и выдаёт E_WARNING , если link уже существует. В Windows функция также не работает и выдаёт E_WARNING , если target не существует.
Примеры
Пример #1 Создание символической ссылки
$target = ‘uploads.php’ ;
$link = ‘uploads’ ;
symlink ( $target , $link );
?php
Смотрите также
- link() — Создаёт жёсткую ссылку
- readlink() — Возвращает файл, на который указывает символическая ссылка
- linkinfo() — Возвращает информацию о ссылке
- unlink() — Удаляет файл
User Contributed Notes 20 notes
Here is a simple way to control who downloads your files.
You will have to set: $filename, $downloaddir, $safedir and $downloadURL.
Basically $filename is the name of a file, $downloaddir is any dir on your server, $safedir is a dir that is not accessible by a browser that contains a file named $filename and $downloadURL is the URL equivalent of your $downloaddir.
The way this works is when a user wants to download a file, a randomly named dir is created in the $downloaddir, and a symbolic link is created to the file being requested. The browser is then redirected to the new link and the download begins.
The code also deletes any past symbolic links created by any past users before creating one for itself. This in effect leaves only one symbolic link at a time and prevents past users from downloading the file again without going through this script. There appears to be no problem if a symbolic link is deleted while another person is downloading from that link.
This is not too great if not many people download the file since the symbolic link will not be deleted until another person downloads the same file.
$letters = ‘abcdefghijklmnopqrstuvwxyz’ ;
srand ((double) microtime () * 1000000 );
$string = » ;
for ( $i = 1 ; $i $q = rand ( 1 , 24 );
$string = $string . $letters [ $q ];
>
$handle = opendir ( $downloaddir );
while ( $dir = readdir ( $handle )) <
if ( is_dir ( $downloaddir . $dir )) <
if ( $dir != «.» && $dir != «..» ) <
@ unlink ( $downloaddir . $dir . «/» . $filename );
@ rmdir ( $downloaddir . $dir );
>
>
>
closedir ( $handle );
mkdir ( $downloaddir . $string , 0777 );
symlink ( $safedir . $filename , $downloaddir . $string . «/» . $filename );
Header ( «Location: » . $downloadURL . $string . «/» . $filename );
?>
link
Возвращает true в случае успешного выполнения или false в случае возникновения ошибки.
Ошибки
Функция завершается с ошибкой и выдаёт E_WARNING , если link уже существует или если target не существует.
Примеры
Пример #1 Создание простой жёсткой ссылки
$target = ‘source.ext’ ; // Это уже существующий файл
$link = ‘newfile.ext’ ; // Это файл, который вы хотите привязать к первому
?php
Примечания
Замечание: Эта функция неприменима для работы с удалёнными файлами, поскольку файл должен быть доступен через файловую систему сервера.
Замечание: Только для Windows: Для данной функции необходимо, чтобы PHP был запущен в привилегированном режиме или с отключённым UAC.
Смотрите также
- symlink() — Создаёт символическую ссылку
- readlink() — Возвращает файл, на который указывает символическая ссылка
- linkinfo() — Возвращает информацию о ссылке
- unlink() — Удаляет файл
User Contributed Notes 4 notes
in unix/linux:
hardlinks (by this function) cannot go across different filesystems.
softlinks can point anywhere.
in linux, hardlinking to directory is not permited.
For a backup utility I needed link-like functionality on a windows system. As it isn’t availible on windows, i tried to do it myself with the help of some tools. All you need is junction.exe from sysinternals in your %PATH%.
if(! function_exists ( ‘link’ )) < // Assume a windows system
function link ( $target , $link ) if( is_dir ( $target )) // junctions link to directories in windows
exec ( «junction $link $target » , $lines , $val );
return 0 == $val ;
>elseif( is_file ( $target )) // Hardlinks link to files in windows
exec ( «fsutil hardlink create $link $target » , $lines , $val );
return 0 == $val ;
>
I noticed that, differently from Unix ln command, the second parameter can´t be a directory name, i.e., if you want to create a link with the same filename of the target file (obviously on different directories), you must specify the filename on the link parameter.
Example:
Unix ln command:
ln /dir1/file /dir2/ // ok, creates /dir2/file link
PHP link function:
link («/dir1/file», «/dir2/»); // wrong, gives a «File exists» warning
link («/dir1/file», «/dir2/file»); // ok, creates /dir2/file link
In at least php-5.3 (linux-2.6.38.6) a process owned by apache could make a link() in a directory owned by apache, to a file owned by webmaster to which it had group read permissions. In php-7.0 (linux-4.13.16) that results in a «permission denied». Either the target file must be owned by apache or one must use copy() instead (so that ownership changes to apache).
PHP symlink() Function
The symlink() function creates a symbolic link from the existing target with the specified name link.
Note: This is not an HTML link, but a link in the filesystem.
Syntax
Parameter Values
Parameter | Description |
---|---|
target | Required. Specifies the target of the link |
link | Required. Specifies the link name |
Technical Details
Return Value: | TRUE on success, FALSE on failure |
---|---|
PHP Version: | 4.0+ |
PHP Changelog: | PHP 5.3: Available on Windows platforms |
❮ PHP Filesystem Reference
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Ссылку создавать файл php
Иногда требуется создать символические ссылки на хостинге посредством скрипта php. Для этого можно использовать следующий скрипт: $target = ‘/home/devfix/public_html/labinsk24.ru/upload’;
$link = ‘upload’;
symlink($target, $link); echo readlink($link);
?>?php
- info@devfix.ru +7 952 985 89 44 —>
- 385132 Краснодар, Тургеневское шоссе, 27 (встречи требуют предварительного согласования)
- «1С-Битрикс» — Управление сайтом
- HTML
- CSS
- PHP
- AJAX
- MySQL
- Twitter Bootstrap
- Создание сайтов
- Поддержка сайтов
- Оптимизация сайтов
- Администрирование серверов
- Копирайтинг
- Наполнение сайтов
- Понедельник: 10:00 — 18:00
- Вторник: 10:00 — 18:00
- Среда: 10:00 — 18:00
- Четверг: 10:00 — 18:00
- Пятница: 10:00 — 18:00
- Суббота: Выходной
- Воскресенье: Выходной
Обратная связь
Авторизация
Once you’ve subscribed your user, you’d send their subscription to your server to store in a database so that when you want to send a message you can lookup the subscription and send a message to it.
To simplify things for this code lab copy the following details into the Push Companion Site and it’ll send a push message for you, using the application server keys on the site — so make sure they match.