0

Ok, I am trying to create a symbolic link using php symlink() function, but am not fully understanding it. Here is what the issue is.

I have several folders on a network share that has been mounted in the following location:

/home/metaimage
/home/opmadbexports

Now, I need to symlink these inside of a drupal installation located at the following location:

/home/opmadbdev/html/

I'm unsure of how to do this. FollowSymLinks is on. I just need to code to create a symbolic link and then kill the symbolic link.

EDIT EDIT EDIT

/home/metaimage AND /home/opmadbexports

are both outside the DOCUMENT_ROOT. Not sure if that would be causing me the issues I'm having. Perhaps an alias is a better idea?

Thanks!

Adam J
  • 506
  • 3
  • 17
  • The question is the code to symlink() the above folders inside of a php script. And then unlink it. See the last sentence. – Adam J Mar 13 '12 at 17:56

2 Answers2

1

This code should do it:

// Syntax is :  symlink ('Where the link point to',  'Name of the link to create');
symlink('/home/metaimage',         '/home/opmadbdev/html/metaimage');
symlink('/home/opmadbexports',     '/home/opmadbdev/html/opmadbexports');

// do stuff

unlink('/home/opmadbdev/html/metaimage');
unlink('/home/opmadbdev/html/opmadbexports');
roychri
  • 2,866
  • 1
  • 21
  • 29
  • This is not working. I am unsure if the root directory is not available to this user. – Adam J Mar 13 '12 at 18:12
  • No, I don't get any errors. I set up an if statement to let me know if the symbolic link was successful, and it wasn't. It gives me a giant F-you (cause I told it to), and won't continue. Maybe I should mention that /home/metaimage is outside of the Document Root? – Adam J Mar 13 '12 at 18:19
  • LOL! :) How do you test if the link was successful precisly? If you have FollowSymLink then it should not matter where the link point to. – roychri Mar 13 '12 at 18:30
  • What I'm doing is the following: if (!symlink('/home/metaimage', '/home/opmadbdev/html/metaimage')) { print 'something'; exit; } – Adam J Mar 13 '12 at 18:31
  • And even leaving it in there, but then commenting out the unlink, when I go in under command line, it is not symlinked. – Adam J Mar 13 '12 at 18:38
  • Maybe the user who runs this symlink (apache or nobody or httpd) does not have permissions to write in /home/opmadbdev/html folder. You can find who is running the php script with this: `getmypid()` – roychri Mar 13 '12 at 18:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8835/discussion-between-roychri-and-webdevsoup) – roychri Mar 13 '12 at 18:43
0

Ok, I got it all figured out. While roychri was on the right track, what I ended up doing was mounting the folders inside the web root, but using .htaccess to disable php. I needed to avoid backing up all the files once they were mounted, seeing as there are a ton of files.

Once that was done, I was able to use the scripts I had previously written in order to complete the process.

Adam J
  • 506
  • 3
  • 17