I'm trying to create a symlink with PHP specifying the original path and the link path.
My paths are:
/tx/file.jpg
/sym.php
And this is the code:
symlink("tx/file.jpg","tx/link.jpg");
And it doesn't work, it doesn't give me errors neither in the logs, it just doesn't create the symlink.
I've even tried using:
symlink(getcwd() . "/tx/file.jpg", getcwd() . "/tx/link.jpg");
Without luck.
If instead I move the script in the /tx/ directory and I run:
symlink("file.jpg","link.jpg");
It works.
Why? How can I fix it? I'm on a CentOS 5 server.
The path of a symlink is relative to the directory the symlink resides in, not your current working directory! As such, the link you're creating is referring to what you'd call tx/tx/file.jpg
, which doesn't exist. You will need to create it as:
symlink("file.jpg", "tx/link.jpg");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.